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()
{
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;

View File

@ -6,26 +6,23 @@ class BasicBlockHighlighter;
#include "Cutter.h"
#include <map>
struct BasicBlock
{
RVA address;
QColor color;
};
typedef std::map<RVA, BasicBlock *>::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<RVA, BasicBlock *> bbMap;
std::map<RVA, BasicBlock> bbMap;
};
#endif // BASICBLOCKHIGHLIGHTER_H