From 21a10057df0987873c2d3f50949ac996e4235331 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 9 Jan 2018 12:18:10 +0300 Subject: [PATCH] Protect CKeyHolderStorage via mutex (#1834) --- src/privatesend-util.cpp | 3 +++ src/privatesend-util.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/privatesend-util.cpp b/src/privatesend-util.cpp index a1ef639fc..e350ad3c8 100644 --- a/src/privatesend-util.cpp +++ b/src/privatesend-util.cpp @@ -27,12 +27,14 @@ CScript CKeyHolder::GetScriptForDestination() const const CKeyHolder& CKeyHolderStorage::AddKey(CWallet* pwallet) { + LOCK(cs_storage); storage.emplace_back(std::unique_ptr(new CKeyHolder(pwallet))); LogPrintf("CKeyHolderStorage::%s -- storage size %lld\n", __func__, storage.size()); return *storage.back(); } void CKeyHolderStorage::KeepAll(){ + LOCK(cs_storage); if (storage.size() > 0) { for (auto &key : storage) { key->KeepKey(); @@ -44,6 +46,7 @@ void CKeyHolderStorage::KeepAll(){ void CKeyHolderStorage::ReturnAll() { + LOCK(cs_storage); if (storage.size() > 0) { for (auto &key : storage) { key->ReturnKey(); diff --git a/src/privatesend-util.h b/src/privatesend-util.h index f6bfede8a..a6c4535fb 100644 --- a/src/privatesend-util.h +++ b/src/privatesend-util.h @@ -27,6 +27,7 @@ class CKeyHolderStorage { private: std::vector > storage; + mutable CCriticalSection cs_storage; public: const CKeyHolder& AddKey(CWallet* pwalletIn);