Skip to content

Review finding: shutdown from a nested modal loop can delete the wallet view under it #328

Closed

Description

@kiwidream

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 in requestShutdown, which detectShutdown can enter from any nested event loop), src/qt/sendcoinsdialog.cpp:764-769 → :957-963, src/qt/askpassphrasedialog.cpp:136,151,278 (stack QMessageBox objects parented to the dialog), src/qt/walletview.cpp:261-265 (stack unlock dialog parented to WalletView).

  • Scenario: qbit-cli stop or SIGTERM arrives while a modal dialog runs a nested event loop and its parent chain ends in a WalletView. Examples are the Send confirmation (confirmationDialog->exec()), the unlock passphrase dialog, and Encrypt Wallet's confirmation or result box. The 200 ms poll then runs requestShutdown inside that loop, and removeAllWallets() deletes the WalletView and its children.

    • The heap confirmation dialog is handled by QDialog::exec's guard, but finishSendWithPreparedTransaction(Rejected) then writes members of the freed SendCoinsDialog.
    • The stack-allocated QMessageBox/AskPassphraseDialog children are deleted 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-275 expects the dialog to be deleted during the result box, but the stack QMessageBox parented to this makes that path crash before its QPointer check.

  • Evidence: Code trace. Not reproduced. removeAllWallets() is present at 70fea84f5b: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

  1. added
    bug
    on Nov 4, 2026
  2. kiwidream commented on Nov 11, 2026

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #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 RPC stop/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.x does not close issues automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions