From: Martin Quinson Date: Wed, 25 Sep 2019 11:00:50 +0000 (+0200) Subject: fix a memleak coming from cyclic references in smart pointers X-Git-Tag: v3.24~67^2^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/07c1b80cf296c0aa4995b4a85c05d376329b540b fix a memleak coming from cyclic references in smart pointers Before that change, the SMPI extension of actors got a smart reference onto the S4U actor. That prevented S4U actors from being garbage collected, since a SMPI extension is freed (and its smart references released) only when the S4U actor is destroyed. The change of this commit simply replace smart references with dumb pointers to break the deadlock in the reference cycle, so that s4u actors get collected after use. --- diff --git a/src/smpi/include/smpi_actor.hpp b/src/smpi/include/smpi_actor.hpp index 95e34655c8..de11f688ec 100644 --- a/src/smpi/include/smpi_actor.hpp +++ b/src/smpi/include/smpi_actor.hpp @@ -28,7 +28,7 @@ class ActorExt { std::string instance_id_; bool replaying_ = false; /* is the process replaying a trace */ smpi_trace_call_location_t trace_call_loc_; - s4u::ActorPtr actor_ = nullptr; + s4u::Actor* actor_ = nullptr; smpi_privatization_region_t privatized_region_ = nullptr; #ifdef __linux__ int optind_ = 0; /*for getopt replacement */ @@ -48,7 +48,7 @@ class ActorExt { public: static simgrid::xbt::Extension EXTENSION_ID; - explicit ActorExt(s4u::ActorPtr actor); + explicit ActorExt(s4u::Actor* actor); ActorExt(const ActorExt&) = delete; ActorExt& operator=(const ActorExt&) = delete; ~ActorExt(); diff --git a/src/smpi/internals/smpi_actor.cpp b/src/smpi/internals/smpi_actor.cpp index d363eb5879..e960accf4d 100644 --- a/src/smpi/internals/smpi_actor.cpp +++ b/src/smpi/internals/smpi_actor.cpp @@ -21,7 +21,7 @@ namespace simgrid { namespace smpi { simgrid::xbt::Extension ActorExt::EXTENSION_ID; -ActorExt::ActorExt(s4u::ActorPtr actor) : actor_(actor) +ActorExt::ActorExt(s4u::Actor* actor) : actor_(actor) { if (not simgrid::smpi::ActorExt::EXTENSION_ID.valid()) simgrid::smpi::ActorExt::EXTENSION_ID = simgrid::s4u::Actor::extension_create(); @@ -240,7 +240,7 @@ void ActorExt::init() // set the process attached to the mailbox ext->mailbox_small_->set_receiver(ext->actor_); - XBT_DEBUG("<%ld> SMPI process has been initialized: %p", ext->actor_->get_pid(), ext->actor_.get()); + XBT_DEBUG("<%ld> SMPI process has been initialized: %p", ext->actor_->get_pid(), ext->actor_); } int ActorExt::get_optind()