@@ -162,10 +162,14 @@ bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet
162162
163163 // Unregister with the validation interface which also drops shared pointers.
164164 wallet->m_chain_notifications_handler .reset ();
165- LOCK (context.wallets_mutex );
166- std::vector<std::shared_ptr<CWallet>>::iterator i = std::find (context.wallets .begin (), context.wallets .end (), wallet);
167- if (i == context.wallets .end ()) return false ;
168- context.wallets .erase (i);
165+ {
166+ LOCK (context.wallets_mutex );
167+ std::vector<std::shared_ptr<CWallet>>::iterator i = std::find (context.wallets .begin (), context.wallets .end (), wallet);
168+ if (i == context.wallets .end ()) return false ;
169+ context.wallets .erase (i);
170+ }
171+ // Notify unload so that upper layers release the shared pointer.
172+ wallet->NotifyUnload ();
169173
170174 // Write the wallet setting
171175 UpdateWalletSetting (chain, name, load_on_start, warnings);
@@ -249,10 +253,6 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
249253 auto it = g_unloading_wallet_set.insert (name);
250254 assert (it.second );
251255 }
252- // The wallet can be in use so it's not possible to explicitly unload here.
253- // Notify the unload intent so that all remaining shared pointers are
254- // released.
255- wallet->NotifyUnload ();
256256
257257 // Time to ditch our shared_ptr and wait for ReleaseWallet call.
258258 wallet.reset ();
0 commit comments