Skip to content

Commit

Permalink
delete assignment operators on PrivateKey
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn authored and hoffmang9 committed Nov 6, 2020
1 parent 8ac7fca commit ee71adc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/privatekey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,6 @@ PrivateKey::PrivateKey(PrivateKey &&k)

PrivateKey::~PrivateKey() { if(keydata !=NULL) Util::SecFree(keydata); }

PrivateKey& PrivateKey::operator=(PrivateKey const& k) &
{
if (!keydata) AllocateKeyData();
bn_copy(*keydata, *k.keydata);
return *this;
}

PrivateKey& PrivateKey::operator=(PrivateKey&& k) &
{
if (keydata) Util::SecFree(keydata);
keydata = std::exchange(k.keydata, nullptr);
return *this;
}
>>>>>>> fix resource management in PrivateKey class. add assignment operators to properly copy value (instead of pointer) or move (instead of copying pointer, resulting in double-free)

G1Element PrivateKey::GetG1Element() const
{
g1_t *p = Util::SecAlloc<g1_t>(1);
Expand Down
4 changes: 2 additions & 2 deletions src/privatekey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class PrivateKey {
PrivateKey(const PrivateKey &k);
PrivateKey(PrivateKey &&k);

PrivateKey& operator=(PrivateKey const&) &;
PrivateKey& operator=(PrivateKey&&) &;
PrivateKey& operator=(PrivateKey const&) = delete;
PrivateKey& operator=(PrivateKey&&) = delete;

~PrivateKey();

Expand Down

0 comments on commit ee71adc

Please sign in to comment.