Skip to content

qbit-qt shutdown can access a destroyed WalletModel during transaction preparation #80

Closed

Description

@kiwidream

Report

Current behaviour

Whole-application shutdown can destroy a wallet model before the wallet view that uses it.

BitcoinApplication::requestShutdown() deletes m_wallet_controller while the main window and its wallet views remain alive until BitcoinApplication is destroyed. Each WalletModel is parented to the controller, so deleting the controller also deletes its models. Unlike ordinary wallet removal, this path does not emit walletRemoved and destroy the corresponding WalletView first.

This leaves an in-flight SendCoinsDialog with a raw WalletModel*. Its background preparation worker queues completion to the still-live dialog, and prepareTransactionFinished() dereferences that model. The QPointer<SendCoinsDialog> protects the dialog lifetime, but not the model lifetime. For a wallet that was initially locked, UnlockContext::~UnlockContext() can also attempt to relock through the destroyed model.

Depending on timing, quitting while a transaction is being prepared can therefore cause undefined behaviour or a crash. It can also leave the user without a clear final disposition for the attempted send.

Expected behaviour

Application shutdown should quiesce or destroy wallet views, preparation workers, queued completions, and unlock contexts before their WalletModel objects are destroyed. Quitting during transaction preparation should always complete cleanly within a bounded time and must not access deleted Qt objects.

Steps to reproduce

A deterministic regression should use a latch because the failing window is timing-dependent:

  1. Build qbit-qt with wallet support and AddressSanitizer.
  2. Create and fund an encrypted wallet, leave it initially locked, and prepare a transaction with enough inputs to keep background preparation active.
  3. Pause the preparation worker immediately before it queues prepareTransactionFinished(), or pause delivery after the completion has been queued.
  4. Request application Quit and wait until WalletController and its child WalletModel have been destroyed.
  5. Release the worker while the GUI event loop is still processing events.
  6. Verify that shutdown exits cleanly without a model use-after-free.
  7. Repeat with completion delivery suppressed and verify that UnlockContext teardown does not relock through a deleted model.

The source-level lifetime ordering is clear, but a full-application ASAN reproduction has not yet been attached.

Relevant code

Suggested fix direction

Tear down or synchronously quiesce wallet views before deleting m_wallet_controller. Ensure preparation workers, queued callbacks, and unlock contexts cannot outlive their model. A guarded model pointer can provide defense in depth, but shutdown ordering should still establish one clear owner and lifetime boundary.

Add latch-controlled Qt tests for shutdown before completion, after completion is queued, and with an initially locked wallet. Run them under ASAN and retain coverage for ordinary wallet unload.

Version and platform

  • Reproduced by source inspection on main at 7e48b45f2a8e75268fd1fd44d0091a4bdde2377e.
  • Also applies to 0.1.x at 2fc5bfe9ce062641e6e663edd46c3059b3e7fe9b; the relevant files are identical.
  • Platform: all Qt-supported platforms in principle; a full runtime reproduction is still pending.
  • Build source: compiled from source.

Activity

  1. added
    bug
    on Jul 10, 2026
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