Protect CKeyHolderStorage via mutex (#1834)
This commit is contained in:
parent
d69ad9d619
commit
c532be1c06
@ -27,12 +27,14 @@ CScript CKeyHolder::GetScriptForDestination() const
|
|||||||
|
|
||||||
const CKeyHolder& CKeyHolderStorage::AddKey(CWallet* pwallet)
|
const CKeyHolder& CKeyHolderStorage::AddKey(CWallet* pwallet)
|
||||||
{
|
{
|
||||||
|
LOCK(cs_storage);
|
||||||
storage.emplace_back(std::unique_ptr<CKeyHolder>(new CKeyHolder(pwallet)));
|
storage.emplace_back(std::unique_ptr<CKeyHolder>(new CKeyHolder(pwallet)));
|
||||||
LogPrintf("CKeyHolderStorage::%s -- storage size %lld\n", __func__, storage.size());
|
LogPrintf("CKeyHolderStorage::%s -- storage size %lld\n", __func__, storage.size());
|
||||||
return *storage.back();
|
return *storage.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeyHolderStorage::KeepAll(){
|
void CKeyHolderStorage::KeepAll(){
|
||||||
|
LOCK(cs_storage);
|
||||||
if (storage.size() > 0) {
|
if (storage.size() > 0) {
|
||||||
for (auto &key : storage) {
|
for (auto &key : storage) {
|
||||||
key->KeepKey();
|
key->KeepKey();
|
||||||
@ -44,6 +46,7 @@ void CKeyHolderStorage::KeepAll(){
|
|||||||
|
|
||||||
void CKeyHolderStorage::ReturnAll()
|
void CKeyHolderStorage::ReturnAll()
|
||||||
{
|
{
|
||||||
|
LOCK(cs_storage);
|
||||||
if (storage.size() > 0) {
|
if (storage.size() > 0) {
|
||||||
for (auto &key : storage) {
|
for (auto &key : storage) {
|
||||||
key->ReturnKey();
|
key->ReturnKey();
|
||||||
|
@ -27,6 +27,7 @@ class CKeyHolderStorage
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<CKeyHolder> > storage;
|
std::vector<std::unique_ptr<CKeyHolder> > storage;
|
||||||
|
mutable CCriticalSection cs_storage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const CKeyHolder& AddKey(CWallet* pwalletIn);
|
const CKeyHolder& AddKey(CWallet* pwalletIn);
|
||||||
|
Loading…
Reference in New Issue
Block a user