From 35dc676e46666d431a8a6b5062994e42caf3b4ac Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 27 Mar 2017 16:36:08 +0200 Subject: [PATCH] finish to plug ptaskL07 leak network and cpu models share the same lmm as the host model. the host model frees the lmm, but both sub models have to set their local reference to nullptr before the parent destructors are called to prevent double free/delete. --- src/surf/ptask_L07.cpp | 26 +++++++++++++++++++------- src/surf/ptask_L07.hpp | 4 ++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 68203b5687..cc883f5fed 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -45,22 +45,34 @@ HostL07Model::~HostL07Model() { lmm_system_free(maxminSystem_); maxminSystem_ = nullptr; + delete surf_network_model; + delete surf_cpu_model_pm; } CpuL07Model::CpuL07Model(HostL07Model *hmodel,lmm_system_t sys) : CpuModel() , hostModel_(hmodel) - { - maxminSystem_ = sys; - } +{ + maxminSystem_ = sys; +} + +CpuL07Model::~CpuL07Model() +{ + maxminSystem_ = nullptr; +} NetworkL07Model::NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys) : NetworkModel() , hostModel_(hmodel) - { - maxminSystem_ = sys; - loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE); - } +{ + maxminSystem_ = sys; + loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE); +} + +NetworkL07Model::~NetworkL07Model() +{ + maxminSystem_ = nullptr; +} double HostL07Model::nextOccuringEvent(double now) { diff --git a/src/surf/ptask_L07.hpp b/src/surf/ptask_L07.hpp index d5e343820e..4a2d68dc9a 100644 --- a/src/surf/ptask_L07.hpp +++ b/src/surf/ptask_L07.hpp @@ -48,7 +48,7 @@ public: class CpuL07Model : public CpuModel { public: CpuL07Model(HostL07Model *hmodel,lmm_system_t sys); - ~CpuL07Model() = default; + ~CpuL07Model(); Cpu *createCpu(simgrid::s4u::Host *host, std::vector *speedPerPstate, int core) override; HostL07Model *hostModel_; @@ -57,7 +57,7 @@ public: class NetworkL07Model : public NetworkModel { public: NetworkL07Model(HostL07Model *hmodel, lmm_system_t sys); - ~NetworkL07Model() = default; + ~NetworkL07Model(); LinkImpl* createLink(const char* name, double bandwidth, double latency, e_surf_link_sharing_policy_t policy) override; -- 2.20.1