Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/privatesend-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ CScript CKeyHolder::GetScriptForDestination() const

const CKeyHolder& CKeyHolderStorage::AddKey(CWallet* pwallet)
{
LOCK(cs_storage);
storage.emplace_back(std::unique_ptr<CKeyHolder>(new CKeyHolder(pwallet)));
LogPrintf("CKeyHolderStorage::%s -- storage size %lld\n", __func__, storage.size());
return *storage.back();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaks a reference to an unlocked entry in storage. The reference seems to be only used to call GetScriptForDestination() on it. Maybe it's better to change this method to return a copy of the pubKey instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. pubKey is a private member however and since we never actually need anything else but corresponding CScript anyway I guess changing this to return storage.back().GetScriptForDestination(); should do the job.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls see #1840

}

void CKeyHolderStorage::KeepAll(){
LOCK(cs_storage);
if (storage.size() > 0) {
for (auto &key : storage) {
key->KeepKey();
Expand All @@ -44,6 +46,7 @@ void CKeyHolderStorage::KeepAll(){

void CKeyHolderStorage::ReturnAll()
{
LOCK(cs_storage);
if (storage.size() > 0) {
for (auto &key : storage) {
key->ReturnKey();
Expand Down
1 change: 1 addition & 0 deletions src/privatesend-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CKeyHolderStorage
{
private:
std::vector<std::unique_ptr<CKeyHolder> > storage;
mutable CCriticalSection cs_storage;

public:
const CKeyHolder& AddKey(CWallet* pwalletIn);
Expand Down