From 3620538812a9df490ace6b3adf8bd120b7a0027b Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Mon, 1 Jul 2019 00:12:52 +0200 Subject: Fix memory leakages which repeat during program operation. There are some singletons left which are allocated/created during main window content population. Signed-off-by: Pavel Pisa --- qtmips_gui/cacheview.cpp | 4 ++++ qtmips_gui/cacheview.h | 1 + qtmips_gui/coreview/alu.cpp | 7 +++++++ qtmips_gui/coreview/alu.h | 1 + qtmips_gui/coreview/latch.cpp | 9 +++++++++ qtmips_gui/coreview/latch.h | 1 + qtmips_gui/coreview/programcounter.cpp | 5 +++++ qtmips_gui/coreview/programcounter.h | 1 + qtmips_machine/core.cpp | 4 ++++ qtmips_machine/core.h | 1 + 10 files changed, 34 insertions(+) diff --git a/qtmips_gui/cacheview.cpp b/qtmips_gui/cacheview.cpp index 23b5557..bf8733a 100644 --- a/qtmips_gui/cacheview.cpp +++ b/qtmips_gui/cacheview.cpp @@ -387,3 +387,7 @@ CacheViewScene::CacheViewScene(const machine::Cache *cache) { addItem(ablock); ablock->setPos(0, -ablock->boundingRect().height() -16); } + +CacheViewScene::~CacheViewScene() { + delete[] block; +} diff --git a/qtmips_gui/cacheview.h b/qtmips_gui/cacheview.h index 8e7a4fb..6091d6b 100644 --- a/qtmips_gui/cacheview.h +++ b/qtmips_gui/cacheview.h @@ -92,6 +92,7 @@ class CacheViewScene : public QGraphicsScene { Q_OBJECT public: CacheViewScene(const machine::Cache *cache); + ~CacheViewScene(); private: unsigned associativity; diff --git a/qtmips_gui/coreview/alu.cpp b/qtmips_gui/coreview/alu.cpp index e1494cb..5494b3f 100644 --- a/qtmips_gui/coreview/alu.cpp +++ b/qtmips_gui/coreview/alu.cpp @@ -58,6 +58,13 @@ coreview::Alu::Alu() : QGraphicsItem(nullptr), name("ALU", this) { setPos(x(), y()); // set connector's position } +coreview::Alu::~Alu() { + delete con_in_a; + delete con_in_b; + delete con_out; + delete con_ctl; +} + QRectF coreview::Alu::boundingRect() const { return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW); } diff --git a/qtmips_gui/coreview/alu.h b/qtmips_gui/coreview/alu.h index ba87693..e0012e6 100644 --- a/qtmips_gui/coreview/alu.h +++ b/qtmips_gui/coreview/alu.h @@ -44,6 +44,7 @@ namespace coreview { class Alu : public QGraphicsItem { public: Alu(); + ~Alu(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); diff --git a/qtmips_gui/coreview/latch.cpp b/qtmips_gui/coreview/latch.cpp index f0e2db9..e458f9b 100644 --- a/qtmips_gui/coreview/latch.cpp +++ b/qtmips_gui/coreview/latch.cpp @@ -60,6 +60,15 @@ Latch::Latch(machine::QtMipsMachine *machine, qreal height) : QGraphicsObject(nu connect(machine, SIGNAL(tick()), this, SLOT(tick())); } +Latch::~Latch() { + while (!connectors.isEmpty()) { + ConnectorPair cp = connectors.takeFirst(); + delete cp.in; + delete cp.out; + } + delete wedge_animation; +} + QRectF Latch::boundingRect() const { QRectF b(-PENW / 2, -PENW / 2, WIDTH + PENW, height + PENW); b |= title->boundingRect(); diff --git a/qtmips_gui/coreview/latch.h b/qtmips_gui/coreview/latch.h index 4521f9c..565e29c 100644 --- a/qtmips_gui/coreview/latch.h +++ b/qtmips_gui/coreview/latch.h @@ -50,6 +50,7 @@ class Latch : public QGraphicsObject { Q_PROPERTY(QColor wedge_clr READ wedge_color WRITE set_wedge_color) public: Latch(machine::QtMipsMachine *machine, qreal height); + ~Latch(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); diff --git a/qtmips_gui/coreview/programcounter.cpp b/qtmips_gui/coreview/programcounter.cpp index 018bb38..2fb6980 100644 --- a/qtmips_gui/coreview/programcounter.cpp +++ b/qtmips_gui/coreview/programcounter.cpp @@ -65,6 +65,11 @@ ProgramCounter::ProgramCounter(machine::QtMipsMachine *machine) : QGraphicsObjec setPos(x(), y()); // To set initial connectors positions } +ProgramCounter::~ProgramCounter() { + delete con_in; + delete con_out; +} + QRectF ProgramCounter::boundingRect() const { return QRectF(-PENW / 2, -PENW / 2, WIDTH + PENW, HEIGHT + PENW); } diff --git a/qtmips_gui/coreview/programcounter.h b/qtmips_gui/coreview/programcounter.h index 3f981f3..ae5d45d 100644 --- a/qtmips_gui/coreview/programcounter.h +++ b/qtmips_gui/coreview/programcounter.h @@ -47,6 +47,7 @@ class ProgramCounter : public QGraphicsObject { Q_OBJECT public: ProgramCounter(machine::QtMipsMachine *machine); + ~ProgramCounter(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); diff --git a/qtmips_machine/core.cpp b/qtmips_machine/core.cpp index 96ae0ad..3255fbf 100644 --- a/qtmips_machine/core.cpp +++ b/qtmips_machine/core.cpp @@ -60,6 +60,10 @@ Core::Core(Registers *regs, MemoryAccess *mem_program, MemoryAccess *mem_data, step_over_exception[EXCAUSE_INT] = false; } +Core::~Core() { + delete ex_default_handler; +} + void Core::step(bool skip_break) { cycle_c++; emit cycle_c_value(cycle_c); diff --git a/qtmips_machine/core.h b/qtmips_machine/core.h index fd15315..dfa9261 100644 --- a/qtmips_machine/core.h +++ b/qtmips_machine/core.h @@ -72,6 +72,7 @@ class Core : public QObject { public: Core(Registers *regs, MemoryAccess *mem_program, MemoryAccess *mem_data, unsigned int min_cache_row_size = 1, Cop0State *cop0state = nullptr); + ~Core(); void step(bool skip_break = false); // Do single step void reset(); // Reset core (only core, memory and registers has to be reseted separately) -- cgit v1.2.3