diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -42,9 +42,11 @@ #include #include -static std::vector vpwallets; +static CCriticalSection cs_wallets; +static std::vector vpwallets GUARDED_BY(cs_wallets); bool AddWallet(CWallet *wallet) { + LOCK(cs_wallets); assert(wallet); std::vector::const_iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet); @@ -56,6 +58,7 @@ } bool RemoveWallet(CWallet *wallet) { + LOCK(cs_wallets); assert(wallet); std::vector::iterator i = std::find(vpwallets.begin(), vpwallets.end(), wallet); @@ -67,14 +70,17 @@ } bool HasWallets() { + LOCK(cs_wallets); return !vpwallets.empty(); } std::vector GetWallets() { + LOCK(cs_wallets); return vpwallets; } CWallet *GetWallet(const std::string &name) { + LOCK(cs_wallets); for (CWallet *wallet : vpwallets) { if (wallet->GetName() == name) { return wallet;