Skip to content

Commit d9d8984

Browse files
committed
wallet: Use wallet name instead of pointer on unload/release
1 parent 3ca514d commit d9d8984

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,14 @@ std::shared_ptr<CWallet> GetWallet(const std::string& name)
9393

9494
static Mutex g_wallet_release_mutex;
9595
static std::condition_variable g_wallet_release_cv;
96-
static std::set<CWallet*> g_unloading_wallet_set;
96+
static std::set<std::string> g_unloading_wallet_set;
9797

9898
// Custom deleter for shared_ptr<CWallet>.
9999
static void ReleaseWallet(CWallet* wallet)
100100
{
101101
// Unregister and delete the wallet right after BlockUntilSyncedToCurrentChain
102102
// so that it's in sync with the current chainstate.
103+
const std::string name = wallet->GetName();
103104
wallet->WalletLogPrintf("Releasing wallet\n");
104105
wallet->BlockUntilSyncedToCurrentChain();
105106
wallet->Flush();
@@ -108,7 +109,7 @@ static void ReleaseWallet(CWallet* wallet)
108109
// Wallet is now released, notify UnloadWallet, if any.
109110
{
110111
LOCK(g_wallet_release_mutex);
111-
if (g_unloading_wallet_set.erase(wallet) == 0) {
112+
if (g_unloading_wallet_set.erase(name) == 0) {
112113
// UnloadWallet was not called for this wallet, all done.
113114
return;
114115
}
@@ -119,21 +120,21 @@ static void ReleaseWallet(CWallet* wallet)
119120
void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
120121
{
121122
// Mark wallet for unloading.
122-
CWallet* pwallet = wallet.get();
123+
const std::string name = wallet->GetName();
123124
{
124125
LOCK(g_wallet_release_mutex);
125-
auto it = g_unloading_wallet_set.insert(pwallet);
126+
auto it = g_unloading_wallet_set.insert(name);
126127
assert(it.second);
127128
}
128129
// The wallet can be in use so it's not possible to explicitly unload here.
129130
// Notify the unload intent so that all remaining shared pointers are
130131
// released.
131-
pwallet->NotifyUnload();
132+
wallet->NotifyUnload();
132133
// Time to ditch our shared_ptr and wait for ReleaseWallet call.
133134
wallet.reset();
134135
{
135136
WAIT_LOCK(g_wallet_release_mutex, lock);
136-
while (g_unloading_wallet_set.count(pwallet) == 1) {
137+
while (g_unloading_wallet_set.count(name) == 1) {
137138
g_wallet_release_cv.wait(lock);
138139
}
139140
}

0 commit comments

Comments
 (0)