Skip to content

Guard FreqScanner report against a stopped baseband sink - #3189

Merged
f4exb merged 2 commits into
f4exb:masterfrom
dpc00:fix/freqscanner-report-null-sink
Dec 1, 2026
Merged

f4exb merged 2 commits into
f4exb:masterfrom
dpc00:fix/freqscanner-report-null-sink

Conversation

@dpc00

@dpc00 dpc00 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #3188.

FreqScanner::webapiFormatChannelReport() dereferences m_basebandSink without a null check. stop() sets that pointer to nullptr after the worker thread finishes, so a report requested after teardown crashes in webapiReportGet. This is reachable from the MCP scan tool, which reclaims the previous scanner channel before the next scan.

Use the cached scanner sample rate when the sink is gone.

Verified in a local MSVC build: the two-scan sequence that crashed reliably before now completes, and get_channel_report after channel_action {"run": 0} returns normally. The faulting offset was symbolicated against the PDB to FreqScanner::webapiReportGet.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 0 duplication

Metric Results
Complexity 4
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Stopping the channel before the first valid scan can read the uninitialized m_scannerSampleRate value, causing undefined behavior.

1 open issue
What changed in this PR

Addresses #3188 by guarding Frequency Scanner WebAPI reports against a null baseband sink after worker teardown.

Changes:

  • Uses the cached scanner sample rate when the sink is absent.
  • Adds a comment explaining why reports can arrive after teardown.
File Description
plugins/​channelrx/​freqscanner/​freqscanner.cpp Guards the report’s sample-rate lookup and adds a cached-rate fallback.

Review effort: Balanced

// scanner channel), so fall back to the last known scanner rate instead of
// dereferencing a null pointer.
response.getFreqScannerReport()->setChannelSampleRate(
m_basebandSink ? m_basebandSink->getChannelSampleRate() : m_scannerSampleRate);
The report falls back to m_scannerSampleRate when the baseband sink is
gone, but that member was never initialized and never assigned, so a
report requested after a stop read an indeterminate value. Initialize it
to 0 and keep the last known rate in stop() before the sink is released,
so the fallback reports something real.

Addresses the Copilot review on f4exb#3189.
@f4exb
f4exb merged commit db0915f into f4exb:master Dec 1, 2026
6 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.

FreqScanner: crash requesting a report after the worker has stopped

3 participants