Skip to content

Commit

Permalink
wallet: unload, notify GUI as soon as possible
Browse files Browse the repository at this point in the history
Releases wallet shared pointers prior to doing the
final settings update and prevent GUI races trying
to access a wallet that is no longer loaded.
  • Loading branch information
furszy committed Aug 14, 2024
1 parent 1a41e63 commit 5d15485
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,14 @@ bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet

// Unregister with the validation interface which also drops shared pointers.
wallet->m_chain_notifications_handler.reset();
LOCK(context.wallets_mutex);
std::vector<std::shared_ptr<CWallet>>::iterator i = std::find(context.wallets.begin(), context.wallets.end(), wallet);
if (i == context.wallets.end()) return false;
context.wallets.erase(i);
{
LOCK(context.wallets_mutex);
std::vector<std::shared_ptr<CWallet>>::iterator i = std::find(context.wallets.begin(), context.wallets.end(), wallet);
if (i == context.wallets.end()) return false;
context.wallets.erase(i);
}
// Notify unload so that upper layers release the shared pointer.
wallet->NotifyUnload();

// Write the wallet setting
UpdateWalletSetting(chain, name, load_on_start, warnings);
Expand Down Expand Up @@ -249,10 +253,6 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
auto it = g_unloading_wallet_set.insert(name);
assert(it.second);
}
// The wallet can be in use so it's not possible to explicitly unload here.
// Notify the unload intent so that all remaining shared pointers are
// released.
wallet->NotifyUnload();

// Time to ditch our shared_ptr and wait for ReleaseWallet call.
wallet.reset();
Expand Down

0 comments on commit 5d15485

Please sign in to comment.