@@ -162,10 +162,14 @@ bool RemoveWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet
162
162
163
163
// Unregister with the validation interface which also drops shared pointers.
164
164
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 ();
169
173
170
174
// Write the wallet setting
171
175
UpdateWalletSetting (chain, name, load_on_start, warnings);
@@ -249,10 +253,6 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
249
253
auto it = g_unloading_wallet_set.insert (name);
250
254
assert (it.second );
251
255
}
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 ();
256
256
257
257
// Time to ditch our shared_ptr and wait for ReleaseWallet call.
258
258
wallet.reset ();
0 commit comments