Skip to content

Fix memory leak in rx_samples_c error cleanup waterfall#931

Open
tlozs wants to merge 1 commit into
EttusResearch:masterfrom
tlozs:fix-rx-c-example-cleanup
Open

Fix memory leak in rx_samples_c error cleanup waterfall#931
tlozs wants to merge 1 commit into
EttusResearch:masterfrom
tlozs:fix-rx-c-example-cleanup

Conversation

@tlozs

@tlozs tlozs commented Jun 15, 2026

Copy link
Copy Markdown

Pull Request Details

examples: fix memory leak in rx_samples_c cleanup

Description

This PR fixes an architectural flaw in the goto cleanup waterfall within the rx_samples_c example.

Previously, the free_rx_streamer label was positioned above the free_rx_metadata label. Because C executes sequentially, if an error occurred after the metadata was successfully created (for example, during uhd_usrp_set_rx_rate or uhd_usrp_get_rx_stream), the code would jump to free_rx_metadata, fall through to free_usrp, and exit. It completely skipped free_rx_streamer, silently leaking the streamer memory and leaving the hardware handles dangling.

Changes:

  • Reordered the cleanup labels to strictly follow the reverse-chronological order of resource creation (Metadata -> Streamer -> USRP).
  • Updated the corresponding EXECUTE_OR_GOTO jump targets for the stream setup functions to match the new waterfall order.

Related Issue

N/A

Which devices/areas does this affect?

This affects the C API examples (host/examples/rx_samples_c.c). This is a software-level logic fix and is device-agnostic.

Testing Done

Verified that the updated example compiles successfully. The execution path of the error waterfall was manually traced to guarantee that all UHD handles are safely freed in the correct reverse-chronological sequence upon an initialization failure, eliminating the memory leak and preventing the freeing of unallocated memory.

Checklist

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project. See CODING.md.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes, and all previous tests pass.
  • I have checked all compat numbers if they need updating (FPGA compat,
    MPM compat, noc_shell, specific RFNoC block, ...)

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@tlozs

tlozs commented Jun 15, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant