ADSBDemodSink::processOneSample() updates m_magsqSum, m_magsqPeak, and
m_magsqCount from the sample processing path, while getMagSqLevels()
reads and updates the same statistics when the GUI requests the current
magnitude levels. Thus, two different threads can read and write the
same variables concurrently.
Protect both access paths with a new m_magsqMutex to prevent concurrent
updates and reads of the magnitude statistics.
This eliminates the data race identified by ThreadSanitizer and
prevents the GUI from observing partially updated magnitude statistics
while ADS-B samples are being processed.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
m_running is used to synchronize the PlutoSDR manager and runner
threads. The manager-side startWork() and stopWork() functions control
whether the runner in run() should execute.
startWork() reads m_running before starting the QThread and then waits
for run() to set it true. stopWork() sets m_running false to request
that the runner exit, while run() continuously reads the flag and sets
it false when it terminates.
These accesses occur across the manager and runner threads without
atomic synchronization. Make m_running an atomic_bool in the PlutoSDR
input, output, MIMO input, and MIMO output threads to eliminate the data
race identified by ThreadSanitizer.
This can prevent inconsistent thread state during user-driven device
start, stop, and reload operations, where the GUI can cause the manager
thread to start or stop a PlutoSDR runner while that runner is
processing.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Update the PlutoSDR input, output, and MIMO GUIs to properly handle the
SDRangel device engine entering the StError state following an
asynchronous device failure.
Clear the affected start/stop controls without emitting their signals,
preventing the GUI from attempting to restart or otherwise operate on a
device that has become unavailable. Indicate the error state visually
and display the error message reported by the device engine.
Stop updating device-specific status information while the device engine
is in the error state, since the underlying PlutoSDR device and streaming
resources may already have been closed.
This keeps the GUI state synchronized with the SDRangel device engine
after asynchronous failures such as a disconnected or unavailable
PlutoSDR.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Handle asynchronous errors reported by the PlutoSDR streaming threads and
transition the affected SDRangel device to a stopped and closed state.
When a PlutoSDR acquisition or generation thread reports an error, stop
and destroy the affected streaming threads and release the associated
buffers and device resources. For MIMO devices, shut down both acquisition
and generation paths and close the associated RX and TX resources so the
device is left in a consistent state.
Propagate the failure to the SDRangel device engine using the
DSPAcquisitionError and DSPGenerationError messages, including the
underlying error code and a message indicating that the PlutoSDR needs
to be restarted.
Also guard PlutoSDRInput::start() against an unavailable device parameter
object. This can occur after an asynchronous device failure has already
closed the device and prevents a subsequent start operation from
dereferencing an invalid device state.
This ensures that asynchronous failures such as a disconnected PlutoSDR
or an unrecoverable acquisition or generation error do not leave the
SDRangel device engine running against an unavailable device.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Detect negative return values from rxBufferRefill() and txBufferPush() in
the PlutoSDR input, output, and MIMO worker threads. These calls can fail
asynchronously after the device has successfully started, for example
when the PlutoSDR is disconnected or the underlying I/O connection
encounters an error.
Log the underlying error and emit the error code from the affected worker
thread instead of treating the negative return value as an ordinary
short or incomplete buffer.
This allows asynchronous PlutoSDR acquisition and generation failures to
be propagated out of the worker threads and handled by the device and DSP
error-handling infrastructure, rather than allowing the streaming thread
to continue operating with an invalid device state.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
AddressSanitizer (ASAN) reports a memory leak from the buffer conversion
memory allocated by PlutoSDRInputThread. The memory was not released when
the thread was destroyed, causing the allocation to persist after the
device was closed.
Delete the conversion buffer in the thread destructor so the allocation is
properly released and the leak reported by ASAN is eliminated.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Coverity reported integer overflow before widening when calculating the
sample rate in both ADSBDemodSink and ADSBDemodSinkWorker.
Promote ADS_B_BITS_PER_SECOND to qint64 before multiplication so the
calculations are performed using 64-bit arithmetic.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Coverity reported a potential division by zero when calculating the
preamble correlation.
Guard the correlation calculation against a zero
preambleCorrelationZeros value to avoid undefined behavior when no
zero-chip energy is detected.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
ASAN identified leaked AircraftPathModel instances when the owning
AircraftModel was destroyed.
Pass AircraftModel as the parent of AircraftPathModel so Qt manages the
path model lifetime automatically. This ensures AircraftPathModel instances
are released with their owning AircraftModel.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
ASAN identified an invalid aircraft lifetime during ADS-B aircraft
removal/crash. Clear the highlighted aircraft reference before deleting the
aircraft it points to.
This prevents the GUI from retaining a dangling Aircraft pointer after
the aircraft is removed, and dereferencing the dangling pointer later.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
ASAN reported leaked map animations when no map pipe was available.
Delete the animations and container when there is no consumer.
This ensures dynamically allocated map animation objects are released on
all paths.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Improve ADSBBeastServer client lifetime handling to avoid stale QTcpSocket
pointers remaining in the client list while a deferred deletion is pending.
Previously, close() called deleteLater() on each client and only cleared
m_clients afterwards. This left a window where other code paths could still
encounter sockets that had been scheduled for destruction. The cleanup now
copies the client list, clears the active list first, then disconnects,
closes, and schedules each socket for deletion. This preserves Qt QObject
lifetime rules while ensuring m_clients no longer contains clients that are
being torn down.
Similarly, discardClient() now removes the socket from m_clients before
calling deleteLater(). The sender pointer is also checked before use to avoid
dereferencing an unexpected null sender.
During investigation it was confirmed that ADSBDemodWorker and
ADSBBeastServer are not moved to the processing thread; they retain the thread
affinity of the thread where they are created. As a result, replacing
deleteLater() with immediate delete is unnecessary and could violate Qt
QObject ownership/lifetime expectations if thread affinity assumptions change.
This change keeps deferred deletion semantics while addressing the stale
pointer window.
The ADSBDemodWorker destructor now explicitly stops the heartbeat timer,
closes the Beast server, closes the client socket if needed, and then clears
the input message queue. This provides a more deterministic shutdown path and
ensures network resources are released during worker teardown.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Use the validated bandwidth index when accessing bandwidth tables in the
ChirpChat, MeshCore, and Meshtastic channel GUIs. The previous code used the
raw UI value after clamping it into m_bandwidthIndex, allowing negative or
out-of-range array accesses.
Found by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_rollupState to nullptr in the constructor and set
m_autoNbSymbolsMax to false in resetToDefaults(). This ensures the optional
rollup state pointer and the automatic message length setting have defined
initial values rather than relying on uninitialized storage.
Pointed out by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_radiotext_AB_flag in the RDSParser constructor to ensure the
radio text state is defined before the first Group 2 update.
Keep the flag out of clearUpdateFlags() because it is persistent parser state,
not a transient update flag. Resetting it when update flags are cleared could
incorrectly appear as an A/B transition and cause stale radio text handling.
Pointed out by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Zero-initialize the pilot PLL sample buffer used by BFMDemodSink.
This ensures all four PLL sample values have defined initial values
before they are consumed by the FM stereo processing path and removes
the uninitialized member warning reported by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize the field and vertical sync detection sample counters and
the previous sample value in ATVDemodSink.
This gives the video synchronization state defined initial values when
the sink is constructed and removes the uninitialized member warnings
reported by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize the channel pointer to nullptr and zero-initialize the
synchronous AM demodulation buffer in AMDemodSink.
This ensures both members have defined values when the sink is
constructed and removes the uninitialized member warnings reported by
cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize the m_bytes buffer to zero so all elements have defined
values when an AISDemodSink is constructed.
Detected by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_matchColumn and m_autoTarget in the NotificationSettings
constructor rather than assigning m_matchColumn in the constructor body.
This ensures both members are initialized before the constructor body
executes and removes the uninitialized m_autoTarget member.
Detected by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Value-initialize the Interogator airspace member so it has a defined
state when an Interogator is constructed.
Found by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize the CPR latitude and longitude state when an Aircraft is
created so the position data has defined values before the first CPR
calculation.
Found by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_channel to nullptr in the ChannelPowerSink constructor to
ensure the pointer has a defined value before a channel is assigned.
Found by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_scopeGUI to nullptr in the settings constructor. The pointer
was not initialized and is only assigned through setScopeGUI().
Detected by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_useReverseAPI to false when resetting Interferometer settings
to their defaults. The member was not initialized by the constructor or
resetToDefaults(), allowing its value to be read before being set.
Detected by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_useReverseAPI to false when resetting DOA2 settings to their
defaults. The member was not initialized by the constructor or
resetToDefaults(), allowing its value to be read before being set.
Detected by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Initialize m_streamIndex to zero in the stream source constructor.
BeamSteeringCWModBaseband subsequently assigns each source its actual
stream index, but initializing the member ensures getStreamIndex() does
not expose an indeterminate value during construction.
Detected by cppcheck.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Avoid incrementing an iterator after it has been invalidated by
QMap::erase() by using the iterator returned from erase().
This fixes undefined behavior when removing a channel from m_channelsMap.
Found by cppcheck.
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>
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>
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>
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>
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>
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>
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>
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>
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>