From 53e1044d8ba0c4e6c8320aa7a39138bfe7d3d1bf Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 23 Oct 2014 15:25:55 -0700 Subject: [PATCH] free CBlockIndex if it is allocated. --- src/bitcoindjs.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 710ae9bf..170e02cd 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -2781,7 +2781,7 @@ async_import_key_after(uv_work_t *req) { */ CBlockIndex * -find_new_block_index(uint256 hash, uint256 hashPrevBlock) { +find_new_block_index(uint256 hash, uint256 hashPrevBlock, bool *is_allocated) { // Check for duplicate BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end()) { @@ -2797,13 +2797,16 @@ find_new_block_index(uint256 hash, uint256 hashPrevBlock) { pindexNew->nHeight = pindexNew->pprev->nHeight + 1; } + *is_allocated = true; + return pindexNew; } static inline void cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local jsblock, bool isNew) { + bool is_allocated = false; if (!cblock_index && isNew) { - cblock_index = find_new_block_index(cblock.GetHash(), cblock.hashPrevBlock); + cblock_index = find_new_block_index(cblock.GetHash(), cblock.hashPrevBlock, &is_allocated); } jsblock->Set(NanNew("hash"), NanNew(cblock.GetHash().GetHex().c_str())); @@ -2878,9 +2881,9 @@ cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local jsblock->Set(NanNew("hex"), NanNew(strHex)); // Freed up elsewhere: - // if (isNew) { - // delete cblock_index; - // } + if (is_allocated) { + delete cblock_index; + } } static inline void