Thanks for the report. The crash log had enough in it to trace this in the source, and the AI's guess is correct. It is a use-after-free, and I found the exact chain that triggers it.
Root cause
IcomSession::fail() (src/core/backends/icom/IcomSession.cpp:186-211) does this:
if (was || !reason.isEmpty())
emit disconnected(reason); // runs the handlers synchronously
...
QTimer::singleShot(0, this, [this] { stop(); m_failing = false; }); // `this` may already be freed
When the radio doesn't answer, here is what happens, all on the GUI thread and all synchronously:
IcomStream::failed → IcomSession::fail("…no answer…")
emit disconnected(reason) → IcomCivBackend::onSessionDisconnected() (IcomCivBackend.cpp:1764). Its last line is emit connectionError(reason).
- →
RadioModel::onConnectionError() (RadioModel.cpp:8965) → emit connectionError(msg)
- →
MainWindow::onConnectionError() (MainWindow.cpp:7481). If the connect was started from the radio chooser or drawer, m_pendingRadioTarget is set (performRadioSwitch, MainWindow_Session.cpp:508), so it calls failRadioSwitch(msg).
failRadioSwitch() (MainWindow_Session.cpp:551-554) sees we're not connected and calls m_radioModel.disconnectFromRadio() directly.
- →
IcomCivBackend::disconnectRadio() → m_session->stop(); m_session.reset(); (IcomCivBackend.cpp:1105-1108). This destroys the IcomSession.
- Control returns to step 2, inside the destroyed object's
fail(). QTimer::singleShot(0, this, …) then calls this->thread() on freed memory and crashes.
Your stack trace matches step 7 frame for frame (IcomSession::fail → QTimer::singleShotImpl → invokeMethodImpl → QObject::thread()). The bad address 0x238 is a field read through a null d_ptr, which fits freed memory that macOS's allocator has zeroed.
Two related points:
- The headless target (
ModelRadioConnectionTarget) already defers its disconnectRadio(), so it isn't affected. Only the GUI radio-switch path tears down synchronously.
~IcomSession() already calls stop(). When the session is destroyed during the emit, the deferred teardown has nothing left to do, so skipping it is safe.
Proposed fix
src/core/backends/icom/IcomSession.cpp, fail(): keep a guard across the emit and return early if a handler destroyed the session:
const QPointer<IcomSession> self(this);
if (was || !reason.isEmpty())
emit disconnected(reason);
if (!self)
return; // a handler tore the session down; ~IcomSession() already ran stop()
QTimer::singleShot(0, this, [this] { stop(); m_failing = false; });
Optional second layer: in MainWindow::failRadioSwitch(), defer the disconnectFromRadio() call with QTimer::singleShot(0, …) so a backend's error emit can never destroy the backend's own session mid-call. The other backends (HL2, ANAN, Flex) are exposed to the same re-entry pattern. I'd still keep the IcomSession guard, since it costs nothing and protects every other subscriber too.
Regression test: tests/icom_session_lease_test.cpp (or a small new test) can connect a handler to IcomSession::disconnected that deletes the session, then trigger fail() through a stream failure. Without the guard this crashes under ASan; with it, the test passes and nothing fires after the session is destroyed.
Handoff summary
- Known: a deterministic use-after-free on any failed Icom connect started from the radio chooser. It also covers an unreachable or powered-off IC-7300MK2 or IC-9700. The code dates back to the original backend (feat(icom): Add Icom CIV backend for networked Icom radios #4784) and is platform-independent. macOS just makes it crash reliably.
- Fix: a
QPointer guard after emit disconnected() in IcomSession::fail(), optionally a deferred disconnectFromRadio() in failRadioSwitch(), plus a regression test.
- Workaround until then: connecting from the Connection panel instead of the radio chooser or drawer most likely avoids the synchronous teardown. Make sure the radio is powered on and reachable before you connect.
🤖 aethersdr-agent · cost: $0.6994 · model: claude-opus-5-5
📍 Citation health check (Foundry Constitution Principle I): 1 resolved, 6 unresolved against /Users/aetherclaude/workspace/AetherSDR at origin/main.
Unresolved citations (6)
| Citation |
Reason |
IcomCivBackend.cpp:1105-1108 |
file not found in workspace |
IcomCivBackend.cpp:1764 |
file not found in workspace |
MainWindow.cpp:7481 |
file not found in workspace |
MainWindow_Session.cpp:508 |
file not found in workspace |
MainWindow_Session.cpp:551-554 |
file not found in workspace |
RadioModel.cpp:8965 |
file not found in workspace |