Crash on disconnect while a rigctld client (WSJT-X) is connected (v3.0-beta3)

Brief summary of problem (put in title as well): Crash on disconnect while a rigctld client (WSJT-X) is connected (v3.0-beta3)
Radio Model: Icom IC-7610
Connectivity (USB/Ethernet/Wifi/Other): Ethernet (native Icom LAN)
Operating System: Windows 10 22H2 (x64)
wfview version (press “About”): v3.0-beta3, built from source at tag v3.0-beta3 (Qt 6.10.3, MSVC 2022, x64)
Checked the wfview manual (Y/N): Y
Checked the wfview FAQ (Y/N): Y
Tried to google it (Y/N/NA): Y

What I did:

Connected wfview to the radio, with WSJT-X connected to wfview’s rigctld (Hamlib NET rigctl, port 4532), which polls about once a second. Then pressed Disconnect in wfview.

Expected behavior:

wfview disconnects. The rigctld client is told the rig has gone, and can reconnect later.

Observed behavior:

wfview crashes with an access violation (0xc0000005) right after the log shows “closing tcpServer”. It happens every time while a rigctld client is connected. There were several crash dumps on one day.

From a Debug build’s symbols, the fault is in QHash<funcs, funcType>::findBucket, a rigCaps->commands lookup, called from a socket readyRead handler on the main thread (QAbstractSocketPrivate::canReadNotification → rigCtlClient::socketReadyRead).

Cause: the rig owns rigCaps. Its destructor calls queue->setRigCaps(nullptr), but on the rig thread. rigCtlClient lives on the main thread, so its receiveRigCaps(nullptr) is only queued. disconnectRig() then stops the rig thread, which frees the rig and rigCaps. A rigctld request handled before the queued call runs (WSJT-X polls every second) sees the old non-null rigCaps and reads freed memory. The earlier “rigCaps use-after-free fix” (28970af2) cleared MainController’s and the CW sender’s pointers, but not rigctld’s. The TCI server and the USB controller have the same race, since they run on their own threads.

Fix I tested: a new MainController::releaseRigCapsBeforeRigDeletion(), called in disconnectRig() and in receivePortError()'s teardown before the rig is closed. It:

  • drops the receivers’ queued slot calls,
  • calls queue->setRigCaps(nullptr) from the main thread, so rigctld clients and MainController drop the pointer at once (the rig’s own later call then doesn’t emit again),
  • waits for the TCI and USB controller threads to process it with a blocking no-op invoke. Neither thread blocks on the main thread, so it can’t deadlock.

Tested with WSJT-X connected: no crash. WSJT-X reports a rig-control error and reconnects with Retry. Patch attached (fix-disconnect-rigcaps-crash-patch.txt, 2 files, +41). The patch file was renamed with a .txt extension to allow upload here.

AI disclosure: diagnosed and fixed with Claude Code (Anthropic, Claude Opus 5.5), using the Windows crash dumps, the Debug build’s PDB with cdb, and wfview’s logs.

I tested the fix on my IC-7610.

fix-disconnect-rigcaps-crash-patch.txt (4.6 KB)

Thanks, WD9U / Mark

1 Like

Good catch, Mark. I’ll check it out.

—E

de W6EL

I’m reworking this a little bit, I think there may have been a change or two that weren’t in when you derived the patch. Also found a similar issue with how the initial rigCaps are set. Stand by…

@WD9U merged, thanks!