Skip to content

Fix resource ownership and cleanup issues across several SDRangel components. - #2880

Merged
f4exb merged 9 commits into
f4exb:masterfrom
rgetz:rgetz-fix-resource-leaks
Aug 16, 2026
Merged

Fix resource ownership and cleanup issues across several SDRangel components.#2880
f4exb merged 9 commits into
f4exb:masterfrom
rgetz:rgetz-fix-resource-leaks

Conversation

@rgetz

@rgetz rgetz commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator
  • Release dynamically allocated LeanSDR pipe writers when their owning DVB-S2 decoder and deframer are destroyed.
  • Properly close VISA sessions and unload the dynamically loaded VISA library during cleanup.
  • Avoid creating sample-rate correction messages when they cannot be queued.
  • Release the FFT-based RRC filter when RRCHelper is destroyed.
  • Release aircraft state owned by ObjectMapItem.
  • Transfer newly created frequency lists directly to SWGFreqScannerSettings without leaving the allocation unowned.
  • Release VOR service report messages when the feature message queue is unavailable.

These changes ensure dynamically allocated resources have a corresponding owner and cleanup path, and avoid allocations when ownership cannot be transferred.

The changes address resource leak findings reported by Coverity.

rgetz added 9 commits August 9, 2026 17:14
Coverity reported a resource leak for the bitcount and errcount writers
allocated by opt_writer(). Free them when the FEC decoder helper is
destroyed, matching the existing cleanup used by other LeanSDR components.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
SWGFreqScannerSettings is newly created without a frequency list, so
there is no need to check for or copy into an existing list. Transfer
the newly created frequency list directly to the settings object.

The previous copy path left the newly allocated QList unowned when an
existing frequency list was present. This leaked the list because the
assignment copied its contents rather than transferring ownership.

This also resolves that resource leak identified by Coverity.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Add a destructor to ObjectMapItem to release its owned m_aircraftState.

ObjectMapItem allocates m_aircraftState when aircraft state is present,
but had no corresponding cleanup when the map item was destroyed.

Coverity reported the allocation as a constructor/destructor resource
leak.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Delete the FFT-based RRC filter when RRCHelper is destroyed.

RRCHelper allocates m_filterFFT but the destructor did not release it,
leaking the filter for every RRCHelper instance.

Coverity flagged the missing destructor cleanup as a CTOR_DTOR_LEAK.
The existing destructor already releases the FIR filter and sample buffer,
making the FFT filter cleanup part of the same ownership path.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Free the bitcount and errcount pipe writers owned by s2_fecdec.

The writers are allocated by opt_writer() but were not released when
s2_fecdec was destroyed, causing the allocations to leak.

Coverity reported a CTOR_DTOR_LEAK in the s2_fecdec constructor,
identifying the allocations without corresponding destructor cleanup.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Only allocate `MsgSampleRateCorrection` when a feedback message queue is
available.

The message was previously allocated before checking `m_autoRWBalance`
and `m_feedbackMessageQueue`. When either condition was false, the
message was never queued and its allocation was leaked.

Coverity CID 652413 reported a `RESOURCE_LEAK` after tracing the allocation
from `MsgSampleRateCorrection::create()` to the point where the local pointer
went out of scope without being transferred to the feedback queue.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Unload the dynamically loaded VISA library when the VISA object is
destroyed and ensure radio astronomy VISA sessions are closed first.

Coverity reported a resource leak because `visaLibrary` was loaded with
`LoadLibrary`/`dlopen` but was never released. It also identified
uninitialized VISA function pointers and the library handle.

Initialize the remaining pointers, add platform-specific library cleanup,
and close all radio astronomy instrument sessions before releasing the
default VISA resource manager. The other VISA users were reviewed to
verify that their sessions and default resource managers are also closed
before their VISA objects are destroyed.

The library is only unloaded when no default resource manager session
remains active, avoiding unloading the VISA library while it is still in
use.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Add a destructor to s2_deframer to release the pipewriter objects owned by
state_out and locktime_out.

opt_writer() allocates these pipewriters dynamically when the corresponding
output pipe is provided. Without a destructor, the objects were leaked when
s2_deframer was destroyed.

Coverity reported CTOR_DTOR_LEAK findings for state_out and locktime_out.
The existing leansdr code was reviewed and confirmed that other users of
opt_writer() explicitly delete the resulting pipewriters in their
destructors, so s2_deframer was missing the corresponding cleanup.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
Create and populate the VOR service report message as before, but delete it
when the feature message queue is not available.

The message is normally transferred to `m_msgQueueToFeature` for ownership,
but when the queue is null there is no owner and the allocated message leaked.

Coverity reported the leak as CID 652338 (`RESOURCE_LEAK`) while analyzing
`VorLocalizerWorker::rrNextTurn()`. Review of the surrounding message queue
usage confirmed that queued messages are owned by the queue, making the
missing-queue path the unhandled ownership case.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
@f4exb
f4exb merged commit d8feb80 into f4exb:master Aug 16, 2026
2 of 3 checks passed
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