From 77b93fbab051c826f23f99eaba0d9b1f7c36ad6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Se=C5=86ko?= Date: Wed, 10 Aug 2022 14:01:44 +0300 Subject: [PATCH] Don't leak memory in bb highlighter. --- src/common/BasicBlockHighlighter.cpp | 21 ++++++--------------- src/common/BasicBlockHighlighter.h | 17 +++++++---------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/common/BasicBlockHighlighter.cpp b/src/common/BasicBlockHighlighter.cpp index f81b336b..d8270d44 100644 --- a/src/common/BasicBlockHighlighter.cpp +++ b/src/common/BasicBlockHighlighter.cpp @@ -2,21 +2,14 @@ BasicBlockHighlighter::BasicBlockHighlighter() {} -BasicBlockHighlighter::~BasicBlockHighlighter() -{ - for (BasicBlockIt itr = bbMap.begin(); itr != bbMap.end(); ++itr) { - delete itr->second; - } -} - /** * @brief Highlight the basic block at address */ void BasicBlockHighlighter::highlight(RVA address, const QColor &color) { - BasicBlock *block = new BasicBlock; - block->address = address; - block->color = color; + BasicBlock block; + block.address = address; + block.color = color; bbMap[address] = block; } @@ -33,13 +26,11 @@ void BasicBlockHighlighter::clear(RVA address) * * If there is nothing to highlight at specified address, returns nullptr */ -BasicBlock *BasicBlockHighlighter::getBasicBlock(RVA address) +BasicBlockHighlighter::BasicBlock *BasicBlockHighlighter::getBasicBlock(RVA address) { - BasicBlockIt it; - - it = bbMap.find(address); + auto it = bbMap.find(address); if (it != bbMap.end()) { - return it->second; + return &it->second; } return nullptr; diff --git a/src/common/BasicBlockHighlighter.h b/src/common/BasicBlockHighlighter.h index fc84b32a..2e0825e3 100644 --- a/src/common/BasicBlockHighlighter.h +++ b/src/common/BasicBlockHighlighter.h @@ -6,26 +6,23 @@ class BasicBlockHighlighter; #include "Cutter.h" #include -struct BasicBlock -{ - RVA address; - QColor color; -}; - -typedef std::map::iterator BasicBlockIt; - class BasicBlockHighlighter { public: + struct BasicBlock + { + RVA address; + QColor color; + }; + BasicBlockHighlighter(); - ~BasicBlockHighlighter(); void highlight(RVA address, const QColor &color); void clear(RVA address); BasicBlock *getBasicBlock(RVA address); private: - std::map bbMap; + std::map bbMap; }; #endif // BASICBLOCKHIGHLIGHTER_H