From: Arnaud Giersch Date: Mon, 5 Feb 2018 15:15:21 +0000 (+0100) Subject: Revert "Revert "actually fix the memleak around smpi's process_data" and "try to... X-Git-Tag: v3.19~269 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/be4186e3689b74b38253d5425cbd6d08b2854a2b Revert "Revert "actually fix the memleak around smpi's process_data" and "try to plug a memleak"" This reverts commit c7c5def2870e604025be03b866967c0c5e293afe. --- diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 670f5022c9..147f538aa3 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -165,6 +165,8 @@ public: /** Signal to others that a new actor has been created **/ static simgrid::xbt::signal onCreation; + /** Signal indicating that the given actor is about to disappear */ + static simgrid::xbt::signal onDestruction; /** Create an actor using a function * diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 5e07894d8d..a81f54a2e7 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -22,6 +22,7 @@ namespace simgrid { namespace s4u { simgrid::xbt::signal s4u::Actor::onCreation; +simgrid::xbt::signal s4u::Actor::onDestruction; // ***** Actor creation ***** ActorPtr Actor::self() diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 935ca1b12b..a1982608a4 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -404,6 +404,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn simix_global->process_list[process->pid] = process; XBT_DEBUG("Inserting %s(%s) in the to_run list", process->getCname(), host->getCname()); simix_global->process_to_run.push_back(process); + intrusive_ptr_add_ref(process); /* Tracing the process creation */ TRACE_msg_process_create(process->getName(), process->pid, process->host); @@ -425,7 +426,6 @@ void SIMIX_process_detach() auto process = context->process(); simix_global->cleanup_process_function(process); context->attach_stop(); - delete process; } /** @@ -783,6 +783,7 @@ smx_actor_t SIMIX_process_from_PID(aid_t PID) } void SIMIX_process_on_exit_runall(smx_actor_t process) { + simgrid::s4u::Actor::onDestruction(process->iface()); smx_process_exit_status_t exit_status = (process->context->iwannadie) ? SMX_EXIT_FAILURE : SMX_EXIT_SUCCESS; while (not process->on_exit.empty()) { s_smx_process_exit_fun_t exit_fun = process->on_exit.back(); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 5b0bab3ccf..091dcb2652 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -623,6 +623,13 @@ void SMPI_init(){ simgrid::s4u::Actor::onCreation.connect([](simgrid::s4u::ActorPtr actor) { process_data.insert({actor, new simgrid::smpi::Process(actor, nullptr)}); }); + simgrid::s4u::Actor::onDestruction.connect([](simgrid::s4u::ActorPtr actor) { + if (process_data.find(actor) != process_data.end()) { + delete process_data.at(actor); + process_data.erase(actor); + } + }); + smpi_init_options(); smpi_global_init(); smpi_check_options();