Repository navigation
Description
Summary
Shutdown requested from inside a wallet view's nested modal loop deletes the view under the running loop.
Severity: low. Found in the 2026-11-04 review of the v1.0.1 change set (all 1.x.x merges since v1.0.0 plus the open PRs that target it), against 1.x.x 21fee6ee8e; area: #137.
Observed
Confidence: plausible.
-
Location:
src/qt/bitcoin.cpp:371(removeAllWallets()runs synchronously inrequestShutdown, whichdetectShutdowncan enter from any nested event loop),src/qt/sendcoinsdialog.cpp:764-769→:957-963,src/qt/askpassphrasedialog.cpp:136,151,278(stackQMessageBoxobjects parented to the dialog),src/qt/walletview.cpp:261-265(stack unlock dialog parented toWalletView). -
Scenario:
qbit-cli stopor SIGTERM arrives while a modal dialog runs a nested event loop and its parent chain ends in aWalletView. Examples are the Send confirmation (confirmationDialog->exec()), the unlock passphrase dialog, and Encrypt Wallet's confirmation or result box. The 200 ms poll then runsrequestShutdowninside that loop, andremoveAllWallets()deletes theWalletViewand its children.- The heap confirmation dialog is handled by
QDialog::exec's guard, butfinishSendWithPreparedTransaction(Rejected)then writes members of the freedSendCoinsDialog. - The stack-allocated
QMessageBox/AskPassphraseDialogchildren aredeleted by their parent's destructor, which is an invalid free.
The result is a crash or heap corruption during shutdown. qt: keep Encrypt Wallet responsive during existing-wallet encryption #178's own comment at
askpassphrasedialog.cpp:274-275expects the dialog to be deleted during the result box, but the stackQMessageBoxparented tothismakes that path crash before itsQPointercheck. - The heap confirmation dialog is handled by
-
Evidence: Code trace. Not reproduced.
removeAllWallets()is present at70fea84f5b:src/qt/bitcoin.cpp:365, so this is not a v1.0.1 regression.
Impact
A crash on quit leaves an unclean exit (chainstate not flushed). Wallet data is safe because SQLite is transactional. Upstream Core does not call removeAllWallets() in requestShutdown, so this ordering is qbit-specific (pre-v1.0.0, and #137 extended it).
Suggested fix
In requestShutdown, close any active modal widgets first and defer removeAllWallets() and the controller deletion with QTimer::singleShot(0, ...) once nested loops have unwound. Alternatively, heap-allocate those message boxes and guard callers with QPointer<SendCoinsDialog> after exec(). Add an AppTests case that requests shutdown while the Send confirmation is open. Release-note text is optional.
Related: new (pre-existing).
Activity
kiwidream commentedon Nov 11, 2026
Fixed on
1.x.xby #354 (73c704b4e4), which ships in v1.0.1:requestShutdown()now defers while a dialog's nested event loop is on the stack (the same change that fixes #349), and the RPCstop/SIGTERM poll does not start a shutdown while a modal dialog is open, so the wallet views are no longer deleted under a running dialog.Closing by hand, because a merge into
1.x.xdoes not close issues automatically.