Skip to content

Commit 21a1005

Browse files
committed
Protect CKeyHolderStorage via mutex (#1834)
1 parent d261575 commit 21a1005

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/privatesend-util.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ CScript CKeyHolder::GetScriptForDestination() const
2727

2828
const CKeyHolder& CKeyHolderStorage::AddKey(CWallet* pwallet)
2929
{
30+
LOCK(cs_storage);
3031
storage.emplace_back(std::unique_ptr<CKeyHolder>(new CKeyHolder(pwallet)));
3132
LogPrintf("CKeyHolderStorage::%s -- storage size %lld\n", __func__, storage.size());
3233
return *storage.back();
3334
}
3435

3536
void CKeyHolderStorage::KeepAll(){
37+
LOCK(cs_storage);
3638
if (storage.size() > 0) {
3739
for (auto &key : storage) {
3840
key->KeepKey();
@@ -44,6 +46,7 @@ void CKeyHolderStorage::KeepAll(){
4446

4547
void CKeyHolderStorage::ReturnAll()
4648
{
49+
LOCK(cs_storage);
4750
if (storage.size() > 0) {
4851
for (auto &key : storage) {
4952
key->ReturnKey();

src/privatesend-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CKeyHolderStorage
2727
{
2828
private:
2929
std::vector<std::unique_ptr<CKeyHolder> > storage;
30+
mutable CCriticalSection cs_storage;
3031

3132
public:
3233
const CKeyHolder& AddKey(CWallet* pwalletIn);

0 commit comments

Comments
 (0)