Don't leak memory in bb highlighter.

This commit is contained in:
Kārlis Seņko 2022-08-10 14:01:44 +03:00 committed by Florian Märkl
parent fd42ddb0bb
commit 77b93fbab0
2 changed files with 13 additions and 25 deletions

View File

@ -2,21 +2,14 @@
BasicBlockHighlighter::BasicBlockHighlighter() {} BasicBlockHighlighter::BasicBlockHighlighter() {}
BasicBlockHighlighter::~BasicBlockHighlighter()
{
for (BasicBlockIt itr = bbMap.begin(); itr != bbMap.end(); ++itr) {
delete itr->second;
}
}
/** /**
* @brief Highlight the basic block at address * @brief Highlight the basic block at address
*/ */
void BasicBlockHighlighter::highlight(RVA address, const QColor &color) void BasicBlockHighlighter::highlight(RVA address, const QColor &color)
{ {
BasicBlock *block = new BasicBlock; BasicBlock block;
block->address = address; block.address = address;
block->color = color; block.color = color;
bbMap[address] = block; bbMap[address] = block;
} }
@ -33,13 +26,11 @@ void BasicBlockHighlighter::clear(RVA address)
* *
* If there is nothing to highlight at specified address, returns nullptr * If there is nothing to highlight at specified address, returns nullptr
*/ */
BasicBlock *BasicBlockHighlighter::getBasicBlock(RVA address) BasicBlockHighlighter::BasicBlock *BasicBlockHighlighter::getBasicBlock(RVA address)
{ {
BasicBlockIt it; auto it = bbMap.find(address);
it = bbMap.find(address);
if (it != bbMap.end()) { if (it != bbMap.end()) {
return it->second; return &it->second;
} }
return nullptr; return nullptr;

View File

@ -6,26 +6,23 @@ class BasicBlockHighlighter;
#include "Cutter.h" #include "Cutter.h"
#include <map> #include <map>
class BasicBlockHighlighter
{
public:
struct BasicBlock struct BasicBlock
{ {
RVA address; RVA address;
QColor color; QColor color;
}; };
typedef std::map<RVA, BasicBlock *>::iterator BasicBlockIt;
class BasicBlockHighlighter
{
public:
BasicBlockHighlighter(); BasicBlockHighlighter();
~BasicBlockHighlighter();
void highlight(RVA address, const QColor &color); void highlight(RVA address, const QColor &color);
void clear(RVA address); void clear(RVA address);
BasicBlock *getBasicBlock(RVA address); BasicBlock *getBasicBlock(RVA address);
private: private:
std::map<RVA, BasicBlock *> bbMap; std::map<RVA, BasicBlock> bbMap;
}; };
#endif // BASICBLOCKHIGHLIGHTER_H #endif // BASICBLOCKHIGHLIGHTER_H