From b2ba3f5ea0b7217f73d96496c8239bc1572dce3a Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 9 Feb 2018 20:15:33 -0500 Subject: [PATCH 1/2] Fix memory leak where a new unaltered CClaimTrieNode would be created in addNodeToCache() for the convenient purpose of copying by value, but would never be freed Signed-off-by: Kay Kurokawa --- src/claimtrie.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/claimtrie.cpp b/src/claimtrie.cpp index b44fa255b..a0e120261 100644 --- a/src/claimtrie.cpp +++ b/src/claimtrie.cpp @@ -1220,14 +1220,24 @@ bool CClaimTrieCache::empty() const CClaimTrieNode* CClaimTrieCache::addNodeToCache(const std::string& position, CClaimTrieNode* original) const { - if (!original) - original = new CClaimTrieNode(); - CClaimTrieNode* cacheCopy = new CClaimTrieNode(*original); + // create a copy of the node in the cache, if new node, create empty node + CClaimTrieNode* cacheCopy; + if(!original) + cacheCopy = new CClaimTrieNode(); + else + cacheCopy = new CClaimTrieNode(*original); cache[position] = cacheCopy; + + // check to see if there is the original node in block_originals, + // if not, add it to block_originals cache nodeCacheType::const_iterator itOriginals = block_originals.find(position); if (block_originals.end() == itOriginals) { - CClaimTrieNode* originalCopy = new CClaimTrieNode(*original); + CClaimTrieNode* originalCopy; + if(!original) + originalCopy = new CClaimTrieNode(); + else + originalCopy = new CClaimTrieNode(*original); block_originals[position] = originalCopy; } return cacheCopy; From a2fa2c0720e83dae6f1582e7ec15395e4c697603 Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Fri, 9 Feb 2018 20:16:09 -0500 Subject: [PATCH 2/2] supportExpirationQueueCache was not cleared with the rest of the cache objects Signed-off-by: Kay Kurokawa --- src/claimtrie.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/claimtrie.cpp b/src/claimtrie.cpp index a0e120261..2560610b6 100644 --- a/src/claimtrie.cpp +++ b/src/claimtrie.cpp @@ -2467,6 +2467,7 @@ bool CClaimTrieCache::clear() const supportCache.clear(); supportQueueCache.clear(); supportQueueNameCache.clear(); + supportExpirationQueueCache.clear(); namesToCheckForTakeover.clear(); cacheTakeoverHeights.clear(); return true;