From: Martin Quinson Date: Tue, 26 Apr 2016 15:52:43 +0000 (+0200) Subject: plug 2 memleaks X-Git-Tag: v3_13~30^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7af5f68e45deae49059e1495630646d0c875a6a5 plug 2 memleaks They were "still reachable", but annoying nonetheless. --- diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index 68d3de29af..ecd7f7db52 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -21,6 +21,9 @@ public: /** Constructor, taking the command line parameters of your main function */ Engine(int *argc, char **argv); + /** Finalize the default engine and all its dependencies */ + static void shutdown(); + /** @brief Load a platform file describing the environment * * The environment is either a XML file following the simgrid.dtd formalism, or a lua file. diff --git a/include/simgrid/s4u/mailbox.hpp b/include/simgrid/s4u/mailbox.hpp index f1b2f3ff3a..aa5f3278de 100644 --- a/include/simgrid/s4u/mailbox.hpp +++ b/include/simgrid/s4u/mailbox.hpp @@ -56,6 +56,7 @@ private: std::string name_; smx_mailbox_t inferior_; static boost::unordered_map *mailboxes; + friend s4u::Engine; }; }} // namespace simgrid::s4u diff --git a/include/simgrid/s4u/storage.hpp b/include/simgrid/s4u/storage.hpp index 4b4d98af4e..e67a1a9093 100644 --- a/include/simgrid/s4u/storage.hpp +++ b/include/simgrid/s4u/storage.hpp @@ -40,6 +40,8 @@ XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage); protected: smx_storage_t inferior(); private: + friend s4u::Engine; + static boost::unordered_map *storages_; std::string name_; smx_storage_t inferior_; diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index f7b078e3f5..1f6a490321 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -9,6 +9,8 @@ #include "mc/mc.h" #include "simgrid/s4u/As.hpp" #include "simgrid/s4u/engine.hpp" +#include "simgrid/s4u/mailbox.hpp" +#include "simgrid/s4u/storage.hpp" XBT_LOG_NEW_CATEGORY(s4u,"Log channels of the S4U (Simgrid for you) interface"); using namespace simgrid; @@ -29,6 +31,13 @@ s4u::Engine *s4u::Engine::instance() { return s4u::Engine::instance_; } +void s4u::Engine::shutdown() { + delete s4u::Engine::instance_; + s4u::Engine::instance_ = nullptr; + delete s4u::Mailbox::mailboxes; + delete s4u::Storage::storages_; +} + double s4u::Engine::getClock() { return SIMIX_get_clock(); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index a6a48253f6..4b948c1e0b 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -16,6 +16,7 @@ #include "mc/mc.h" #include "virtual_machine.hpp" #include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals +#include "simgrid/s4u/engine.hpp" XBT_LOG_NEW_CATEGORY(surf, "All SURF categories"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (kernel)"); @@ -348,6 +349,7 @@ void surf_exit(void) tmgr_finalize(); sg_platf_exit(); + simgrid::s4u::Engine::shutdown(); NOW = 0; /* Just in case the user plans to restart the simulation afterward */ }