mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
wallet: unload, notify GUI as soon as possible
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.
This commit is contained in:
parent
1a41e63575
commit
5d15485aaf
1 changed files with 8 additions and 8 deletions
|
@ -162,10 +162,14 @@ bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet
|
||||||
|
|
||||||
// Unregister with the validation interface which also drops shared pointers.
|
// Unregister with the validation interface which also drops shared pointers.
|
||||||
wallet->m_chain_notifications_handler.reset();
|
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);
|
LOCK(context.wallets_mutex);
|
||||||
if (i == context.wallets.end()) return false;
|
std::vector<std::shared_ptr<CWallet>>::iterator i = std::find(context.wallets.begin(), context.wallets.end(), wallet);
|
||||||
context.wallets.erase(i);
|
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
|
// Write the wallet setting
|
||||||
UpdateWalletSetting(chain, name, load_on_start, warnings);
|
UpdateWalletSetting(chain, name, load_on_start, warnings);
|
||||||
|
@ -249,10 +253,6 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
|
||||||
auto it = g_unloading_wallet_set.insert(name);
|
auto it = g_unloading_wallet_set.insert(name);
|
||||||
assert(it.second);
|
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.
|
// Time to ditch our shared_ptr and wait for ReleaseWallet call.
|
||||||
wallet.reset();
|
wallet.reset();
|
||||||
|
|
Loading…
Add table
Reference in a new issue