Skip to content

qt: quitting while a modal dialog is open deletes wallet views under its nested event loop #349

Closed

Description

@kiwidream

Quitting while a modal dialog is open can delete the wallet views underneath that dialog's nested event loop. Objects on that loop caller's stack are then used after they are freed, or destroyed twice. Line numbers are at 1.x.x 21fee6ee8e.

What happens

BitcoinApplication::requestShutdown() calls window->removeAllWallets() (src/qt/bitcoin.cpp:371). That reaches WalletFrame::removeWallet and delete walletView (src/qt/walletframe.cpp:130). It runs inside whatever nested event loop is active, for example:

  • SendCoinsDialog::prepareTransactionFinished waiting in SendConfirmationDialog::exec();
  • the QMessageBox and the file dialog that SendCoinsDialog::presentPSBT keeps on the stack;
  • the AskPassphraseDialog that WalletView keeps on the stack;
  • the AddressBookPage that SendCoinsEntry keeps on the stack.

Deleting the parent destroys these objects while their exec() is still on the stack. Code after exec() then runs on a deleted object.

Calling removeAllWallets() from requestShutdown() is qbit-specific. Upstream only deletes the wallet controller there.

Triggers

  • Guarded: the poll that turns RPC stop and SIGTERM into a shutdown waits while a modal widget is active (src/qt/bitcoin.cpp:267), and the tray menu disables its actions in that case.
  • Not guarded: two triggers have no such check:
    • The application's QEvent::Quit (src/qt/bitcoin.cpp:472), which the platform sends when it asks the app to terminate, for example macOS Dock ▸ Quit, logout, or a Quit Apple event.
    • quitAction → quitRequested → requestShutdown (src/qt/bitcoingui.cpp:410, src/qt/bitcoin.cpp:263). File ▸ Exit can be pressed through accessibility (VoiceOver, UI automation) behind the modal dialog, the same bypass as the Release v1.0.1: test results, remaining fixes, and release gates #174 A11 abort.

Evidence

  • A Qt test under AddressSanitizer deletes the send dialog from the confirmation's nested loop and reports heap-use-after-free in SendCoinsDialog::finishSendWithPreparedTransaction. The send-dialog fix for Release v1.0.1: test results, remaining fixes, and release gates #174 guards that one call site.
  • The other sites were found by reading the code and have not been reproduced in a running app.

Expected

  • A quit request does not delete GUI objects underneath a nested event loop. Either it is deferred while a modal widget is active, as the shutdown poll already does, or the modal dialogs are closed and their loops unwound before the wallet views are deleted.
  • Busy operations (send preparation, PSBT signing, encryption) finish or are cancelled cleanly, and the app then exits without a crash.
  • This is Release v1.0.1: test results, remaining fixes, and release gates #174's check "Quit during background work" (runbook C4): "the app exits, or visibly waits for the operation, without crashing".

Found during the #174 v1.0.1 release work.

Activity

  1. kiwidream commented on Nov 11, 2026

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #354 (73c704b4e4), which ships in v1.0.1: a platform or menu quit, and a wallet unload, now wait while a dialog's nested event loop is running and are carried out once it has closed.

    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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions