Skip to content

SoapyPlutoSDR: close remaining streams during device teardown - #81

Merged
zuckschwerdt merged 1 commit into
pothosware:masterfrom
rrouviere:fix/stream-destructor
Oct 20, 2026
Merged

zuckschwerdt merged 1 commit into
pothosware:masterfrom
rrouviere:fix/stream-destructor

Conversation

@rrouviere

Copy link
Copy Markdown
Contributor

Hi, this PR to ensure that unclosed streams are always closed when destroying the device.
Otherwise, the streams's destructors will be called after iio_context_destroy, which will cause a segfault and (probably) not correctly release hw resources.

Details

Close any remaining RX and TX streams before destroying the libiio context.
This ensure that unclosed streams are always closed when destroying the device, otherwise, the streams's destructors will be called after iio_context_destroy, which will cause a segfault.

SoapyPlutoSDR owns its streamers through std::unique_ptr members, but
C++ destroys those members only after the device destructor body finishes.
The destructor currently destroys the IIO context first, so any remaining
streamer can subsequently attempt to destroy buffers or disable channels
whose context is no longer valid.

Call the existing closeStream() implementation for each remaining stream
while the IIO context is still valid. This releases the streamer resources
in the correct order and performs the normal stream-close cleanup,
including powering down the corresponding LO.

This change provides defensive cleanup when applications don't close their streams explicitly.

Reproduction

Release a PlutoSDR device while a stream remains allocated, for exemple using srsRAN's cell_search:

cell_search -d soapy -a driver=plutosdr -b 3 -s 1300 -e 1301 -n 30 -g 55

With the unmodified plugin, reception succeeded, but the process then
crashed during teardown in iio_buffer_destroy().

This ensure that unclosed streams are always closed when destroying the device.
Otherwise, the streams's destructors will be called after
iio_context_destroy, which will cause a segfault.
@zuckschwerdt

Copy link
Copy Markdown
Member

Sensible to do, yes. Thanks!

@zuckschwerdt
zuckschwerdt merged commit a45594e into pothosware:master Oct 20, 2026
6 checks passed
ATG-wdorsey added a commit to ATG-wdorsey/SoapyPlutoSDR that referenced this pull request Oct 21, 2026
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.

2 participants