From de7381ae49152263bd80f990a2588b40593d6a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89der=20F=2E=20Zulian?= Date: Thu, 22 Jun 2017 12:05:40 +0200 Subject: [PATCH] Fix some segfaults. In the current implementation the object deletion order is important. Messages regarding power and energy are printed inside the Dram destructor. The controller object was destructed and then called by the Dram object. The behavior varies with compiler (clang or gcc). It seems that clang deletes objects later than gcc masking some bugs. --- DRAMSys/simulator/src/simulation/DRAMSys.cpp | 10 +++++----- DRAMSys/simulator/src/simulation/main.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DRAMSys/simulator/src/simulation/DRAMSys.cpp b/DRAMSys/simulator/src/simulation/DRAMSys.cpp index 41b80d42..515c292c 100644 --- a/DRAMSys/simulator/src/simulation/DRAMSys.cpp +++ b/DRAMSys/simulator/src/simulation/DRAMSys.cpp @@ -245,11 +245,6 @@ DRAMSys::~DRAMSys() delete arbiter; - for (auto controller : controllers) - { - delete controller; - } - for (auto dram : drams) { delete dram; @@ -264,6 +259,11 @@ DRAMSys::~DRAMSys() { delete tlmChecker; } + + for (auto controller : controllers) + { + delete controller; + } } void DRAMSys::report(string message) diff --git a/DRAMSys/simulator/src/simulation/main.cpp b/DRAMSys/simulator/src/simulation/main.cpp index 18e00f77..60246caf 100644 --- a/DRAMSys/simulator/src/simulation/main.cpp +++ b/DRAMSys/simulator/src/simulation/main.cpp @@ -78,15 +78,15 @@ int sc_main(int argc, char **argv) std::vector players; // Instantiate DRAMSys: - DRAMSys dramSys("DRAMSys", SimulationXML, resources); + DRAMSys *dramSys = new DRAMSys("DRAMSys", SimulationXML, resources); // Instantiate STL Players: - traceSetup(SimulationXML, resources, &players); + traceSetup *ts = new traceSetup(SimulationXML, resources, &players); // Bind STL Players with DRAMSys: for(auto& p : players) { - p->iSocket.bind(dramSys.tSocket); + p->iSocket.bind(dramSys->tSocket); } // Store the starting of the simulation in wallclock time: @@ -105,5 +105,8 @@ int sc_main(int argc, char **argv) double elapsed_secs = double(clock() - simStartTime) / CLOCKS_PER_SEC; cout << "Simulation took " + to_string(elapsed_secs) + " seconds" << endl; + delete dramSys; + delete ts; + return 0; }