Repository navigation
Description
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:
- Build qbit-qt with wallet support and AddressSanitizer.
- Create and fund an encrypted wallet, leave it initially locked, and prepare a transaction with enough inputs to keep background preparation active.
- Pause the preparation worker immediately before it queues
prepareTransactionFinished(), or pause delivery after the completion has been queued. - Request application Quit and wait until
WalletControllerand its childWalletModelhave been destroyed. - Release the worker while the GUI event loop is still processing events.
- Verify that shutdown exits cleanly without a model use-after-free.
- Repeat with completion delivery suppressed and verify that
UnlockContextteardown 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
WalletModelis parented toWalletController.- Ordinary wallet removal destroys the view before deleting the model.
SendCoinsDialogjoins its preparation thread and releases its unlock context only when the dialog is destroyed.- The worker queues completion to the dialog, while the dialog stores its model as a raw pointer.
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
mainat7e48b45f2a8e75268fd1fd44d0091a4bdde2377e. - Also applies to
0.1.xat2fc5bfe9ce062641e6e663edd46c3059b3e7fe9b; 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