From 9c0329c72b96af50a4bd8e971a31726346835d2d Mon Sep 17 00:00:00 2001 From: warrows Date: Sun, 19 May 2019 19:09:30 +0200 Subject: [PATCH] [zerocoin] Free memory from ToString() Simple fix for a minor memory leak --- src/libzerocoin/bignum_gmp.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libzerocoin/bignum_gmp.cpp b/src/libzerocoin/bignum_gmp.cpp index 58b7580f3b5bd..0d9ac4c4385da 100644 --- a/src/libzerocoin/bignum_gmp.cpp +++ b/src/libzerocoin/bignum_gmp.cpp @@ -196,6 +196,11 @@ std::string CBigNum::ToString(int nBase) const { char* c_str = mpz_get_str(NULL, nBase, bn); std::string str(c_str); + // Free c_str with the right free function: + void (*freefunc)(void *, size_t); + mp_get_memory_functions (NULL, NULL, &freefunc); + freefunc(c_str, strlen(c_str) + 1); + return str; }