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>
Preserve the configuration and center frequency when recreating or
reloading a device of the same device type.
Save the existing device description, serialized settings, and center
frequency before removing the current device. After creating the
replacement, restore the saved settings and frequency when the device
description matches.
For MIMO devices, preserve and restore both the source (RX) and sink (TX)
center frequencies.
This prevents a device reload from unnecessarily resetting the user's
device configuration. In particular, it allows a device that has entered
an error state and needs to be reloaded to return with its previous
configuration instead of requiring the user to configure it again.
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>
Add DSPAcquisitionError and DSPGenerationError messages to provide a
standard mechanism for SDRangel devices to report asynchronous errors
to their DSP device engines.
These errors occur after normal device initialization or startup and are
not the result of a synchronous start or configuration operation. They
cover conditions such as a device being unplugged or disconnected, a
device becoming unavailable, or an error occurring while acquiring or
generating samples.
Handle DSPAcquisitionError in the DSPDeviceSourceEngine and the
acquisition side of DSPDeviceMIMOEngine, and handle DSPGenerationError
in the DSPDeviceSinkEngine and the generation side of
DSPDeviceMIMOEngine. Transition the affected device engine to the error
state and propagate the device-provided error message.
This allows asynchronous failures in a sample source, sample sink, or
MIMO device to be propagated through the SDRangel device engine state
machine instead of leaving the device engine running after the device
has become unavailable or encountered an unrecoverable error.
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 reported leaked aircraft photos when PlaneSpotters was destroyed.
Delete the cached photos during destruction.
This ensures cached photo objects are released when their owning
PlaneSpotters instance goes away.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
ASAN reported leaked flag and airline icons when OsnDB was destroyed.
Add cleanup functions and release the cached icons during destruction.
This ensures cached icon resources do not outlive the OsnDB instance.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
ASAN reported leaked AirportInformation objects when the airport
database was released. Provide a QSharedPointer deleter that deletes
the objects stored in the database hash.
This ensures airport information is released together with its
containing database.
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>
Add a daily GitHub Actions workflow that checks (a) the latest SDRangel
revision against the current Coverity analysis and (b) upload quota before
installing dependencies or starting the build. This avoids unnecessary
runner time when the revision has already been analyzed or Coverity is
not accepting submissions.
When analysis is required and permitted, build SDRangel with Coverity,
collect and upload the results for analysis, helping identify newly
introduced defects before they sit in the code base for too long.
Because Coverity Scan submissions are limited, run the analysis only on
master rather than on pull requests.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Allow ccache usage to be disabled through the ENABLE_CCACHE CMake
option, while preserving the existing automatic detection and
Emscripten exclusion behavior.
This is useful for builds where ccache is available but undesirable,
(like Coverity) and provides clear configuration messages when
ccache is skipped.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Add an ENABLE_LTO option to make link-time optimization configurable on
while keeping it enabled by default.
This allows builds that require LTO to be disabled (add -DENABLE_LTO=OFF),
including builds for Coverity static analysis, without changing the default
optimization settings.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Add a CMake cppcheck module that provides a new "make cppcheck" target
for running cppcheck against the project and generating a html report.
Use compile_commands.json for analysis, ensure generated Qt sources exist
before analysis, support project suppressions and parallel execution, and
generate an HTML report when cppcheck-htmlreport is available.
Cppcheck remains optional and is only required when BUILD_CPPCHECK is
enabled.
Signed-off-by: Robin Getz <rgetz503@gmail.com>
Modernize deprecated CMake usage and correct package-name mismatches
reported by newer CMake versions. Replace exec_program() with
execute_process(), use PkgConfig through find_package() while retaining
fallback discovery, and align find_package_handle_standard_args() names
with their corresponding find_package() calls.
This removes most CMake developer warnings without changing the intended
dependency discovery behavior.
Signed-off-by: Robin Getz <rgetz503@gmail.com>