Skip to content

Commit

Permalink
fix: possible memory leak in Base58
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoatelen-ledger committed Mar 2, 2022
1 parent f6964d9 commit 18034b2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/math/Base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <utils/hex.h>
#include <functional>
#include <crypto/Keccak.h>
#include <vector>

using namespace ledger::core;
static const std::string DIGITS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
Expand Down Expand Up @@ -62,7 +63,7 @@ std::string ledger::core::Base58::encode(const std::vector<uint8_t> &bytes,
pend = len;
while (pbegin != pend && !bytes[pbegin]) pbegin = ++zeros;
const int size = 1 + iFactor * (double)(pend - pbegin);
unsigned char* b58 = new unsigned char[size];
std::vector<unsigned char> b58(size, 0);
for (int i = 0; i < size; i++) b58[i] = 0;
while (pbegin != pend) {
unsigned int carry = bytes[pbegin];
Expand All @@ -82,7 +83,6 @@ std::string ledger::core::Base58::encode(const std::vector<uint8_t> &bytes,
int ri = 0;
while (ri < zeros) { result += base58Dictionary[0]; ri++; }
for (; it2 < size; ++it2) result += base58Dictionary[b58[it2]];
delete[] b58;
return result;
}

Expand Down

0 comments on commit 18034b2

Please sign in to comment.