Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memleaks when exiting early (e.g. with --help or --version).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Apr 2019 13:37:55 +0000 (15:37 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Apr 2019 14:48:59 +0000 (16:48 +0200)
src/include/simgrid/sg_config.hpp
src/simdag/sd_global.cpp
src/simgrid/sg_config.cpp
src/simix/smx_global.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp

index 5e602a5..a9c8c10 100644 (file)
@@ -11,7 +11,6 @@
 /** Config Globals */
 
 XBT_PUBLIC_DATA int _sg_cfg_init_status;
 /** Config Globals */
 
 XBT_PUBLIC_DATA int _sg_cfg_init_status;
-XBT_PUBLIC_DATA bool _sg_cfg_exit_asap;
 
 XBT_PUBLIC void sg_config_init(int* argc, char** argv);
 XBT_PUBLIC void sg_config_finalize();
 
 XBT_PUBLIC void sg_config_init(int* argc, char** argv);
 XBT_PUBLIC void sg_config_finalize();
index bc5f199..f6974f9 100644 (file)
@@ -157,16 +157,13 @@ void SD_init_nocheck(int *argc, char **argv)
 {
   xbt_assert(sd_global == nullptr, "SD_init() already called");
 
 {
   xbt_assert(sd_global == nullptr, "SD_init() already called");
 
-  sd_global = new simgrid::sd::Global();
-
   surf_init(argc, argv);
 
   surf_init(argc, argv);
 
+  sd_global = new simgrid::sd::Global();
+
   simgrid::config::set_default<std::string>("host/model", "ptask_L07");
   if (simgrid::config::get_value<bool>("clean-atexit"))
     atexit(SD_exit);
   simgrid::config::set_default<std::string>("host/model", "ptask_L07");
   if (simgrid::config::get_value<bool>("clean-atexit"))
     atexit(SD_exit);
-  if (_sg_cfg_exit_asap) {
-    exit(0);
-  }
 }
 
 /** @brief set a configuration variable
 }
 
 /** @brief set a configuration variable
index 6358b59..d479532 100644 (file)
@@ -41,15 +41,6 @@ void sg_config_continue_after_help()
  */
 int _sg_cfg_init_status = 0;
 
  */
 int _sg_cfg_init_status = 0;
 
-/* instruct the upper layer (simix or simdag) to exit as soon as possible */
-bool _sg_cfg_exit_asap = false;
-
-#define sg_cfg_exit_early()                                                                                            \
-  do {                                                                                                                 \
-    _sg_cfg_exit_asap = true;                                                                                          \
-    return;                                                                                                            \
-  } while (0)
-
 /* Parse the command line, looking for options */
 static void sg_config_cmd_line(int *argc, char **argv)
 {
 /* Parse the command line, looking for options */
 static void sg_config_cmd_line(int *argc, char **argv)
 {
@@ -120,7 +111,7 @@ static void sg_config_cmd_line(int *argc, char **argv)
     *argc = j;
   }
   if (shall_exit)
     *argc = j;
   }
   if (shall_exit)
-    sg_cfg_exit_early();
+    exit(0);
 }
 
 /* callback of the plugin variable */
 }
 
 /* callback of the plugin variable */
@@ -133,7 +124,7 @@ static void _sg_cfg_cb__plugin(const std::string& value)
 
   if (value == "help") {
     model_help("plugin", surf_plugin_description);
 
   if (value == "help") {
     model_help("plugin", surf_plugin_description);
-    sg_cfg_exit_early();
+    exit(0);
   }
 
   int plugin_id = find_model_description(surf_plugin_description, value);
   }
 
   int plugin_id = find_model_description(surf_plugin_description, value);
@@ -147,7 +138,7 @@ static void _sg_cfg_cb__host_model(const std::string& value)
 
   if (value == "help") {
     model_help("host", surf_host_model_description);
 
   if (value == "help") {
     model_help("host", surf_host_model_description);
-    sg_cfg_exit_early();
+    exit(0);
   }
 
   /* Make sure that the model exists */
   }
 
   /* Make sure that the model exists */
@@ -161,7 +152,7 @@ static void _sg_cfg_cb__cpu_model(const std::string& value)
 
   if (value == "help") {
     model_help("CPU", surf_cpu_model_description);
 
   if (value == "help") {
     model_help("CPU", surf_cpu_model_description);
-    sg_cfg_exit_early();
+    exit(0);
   }
 
   /* New Module missing */
   }
 
   /* New Module missing */
@@ -175,7 +166,7 @@ static void _sg_cfg_cb__optimization_mode(const std::string& value)
 
   if (value == "help") {
     model_help("optimization", surf_optimization_mode_description);
 
   if (value == "help") {
     model_help("optimization", surf_optimization_mode_description);
-    sg_cfg_exit_early();
+    exit(0);
   }
 
   /* New Module missing */
   }
 
   /* New Module missing */
@@ -189,7 +180,7 @@ static void _sg_cfg_cb__storage_mode(const std::string& value)
 
   if (value == "help") {
     model_help("storage", surf_storage_model_description);
 
   if (value == "help") {
     model_help("storage", surf_storage_model_description);
-    sg_cfg_exit_early();
+    exit(0);
   }
 
   find_model_description(surf_storage_model_description, value);
   }
 
   find_model_description(surf_storage_model_description, value);
@@ -202,7 +193,7 @@ static void _sg_cfg_cb__network_model(const std::string& value)
 
   if (value == "help") {
     model_help("network", surf_network_model_description);
 
   if (value == "help") {
     model_help("network", surf_network_model_description);
-    sg_cfg_exit_early();
+    exit(0);
   }
 
   /* New Module missing */
   }
 
   /* New Module missing */
@@ -489,9 +480,6 @@ void sg_config_init(int *argc, char **argv)
 
 void sg_config_finalize()
 {
 
 void sg_config_finalize()
 {
-  if (not _sg_cfg_init_status)
-    return;                     /* Not initialized yet. Nothing to do */
-
   simgrid::config::finalize();
   _sg_cfg_init_status = 0;
 }
   simgrid::config::finalize();
   _sg_cfg_init_status = 0;
 }
index 4a300d8..b463c5a 100644 (file)
@@ -192,10 +192,10 @@ void SIMIX_global_init(int *argc, char **argv)
 #endif
 
   if (simix_global == nullptr) {
 #endif
 
   if (simix_global == nullptr) {
+    surf_init(argc, argv); /* Initialize SURF structures */
+
     simix_global.reset(new simgrid::simix::Global());
     simix_global->maestro_process = nullptr;
     simix_global.reset(new simgrid::simix::Global());
     simix_global->maestro_process = nullptr;
-
-    surf_init(argc, argv);      /* Initialize SURF structures */
     SIMIX_context_mod_init();
 
     // Either create a new context with maestro or create
     SIMIX_context_mod_init();
 
     // Either create a new context with maestro or create
@@ -220,9 +220,6 @@ void SIMIX_global_init(int *argc, char **argv)
 
   if (simgrid::config::get_value<bool>("clean-atexit"))
     atexit(SIMIX_clean);
 
   if (simgrid::config::get_value<bool>("clean-atexit"))
     atexit(SIMIX_clean);
-
-  if (_sg_cfg_exit_asap)
-    exit(0);
 }
 
 int smx_cleaned = 0;
 }
 
 int smx_cleaned = 0;
index 8beb759..d2f6966 100644 (file)
@@ -37,6 +37,11 @@ std::set<std::string> watched_hosts;
 extern std::map<std::string, simgrid::kernel::resource::StorageType*> storage_types;
 
 s_surf_model_description_t* surf_plugin_description = nullptr;
 extern std::map<std::string, simgrid::kernel::resource::StorageType*> storage_types;
 
 s_surf_model_description_t* surf_plugin_description = nullptr;
+static void XBT_ATTRIB_DESTRUCTOR(800) simgrid_free_plugin_description()
+{
+  xbt_free(surf_plugin_description);
+}
+
 XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun)
 {
   static int plugin_amount = 0;
 XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun)
 {
   static int plugin_amount = 0;
@@ -314,8 +319,6 @@ void surf_exit()
   for (auto const& model : all_existing_models)
     delete model;
 
   for (auto const& model : all_existing_models)
     delete model;
 
-  xbt_free(surf_plugin_description);
-
   tmgr_finalize();
   sg_platf_exit();
 
   tmgr_finalize();
   sg_platf_exit();
 
index 6a602cc..38fad62 100644 (file)
@@ -216,10 +216,10 @@ typedef struct surf_model_description s_surf_model_description_t;
 XBT_PUBLIC int find_model_description(s_surf_model_description_t* table, const std::string& name);
 XBT_PUBLIC void model_help(const char* category, s_surf_model_description_t* table);
 
 XBT_PUBLIC int find_model_description(s_surf_model_description_t* table, const std::string& name);
 XBT_PUBLIC void model_help(const char* category, s_surf_model_description_t* table);
 
-#define SIMGRID_REGISTER_PLUGIN(id, desc, init)                       \
-  void simgrid_##id##_plugin_register();                              \
-  void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_##id##_plugin_register() { \
-    simgrid_add_plugin_description(#id, desc, init);                  \
+#define SIMGRID_REGISTER_PLUGIN(id, desc, init)                                                                        \
+  static void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_##id##_plugin_register()                                             \
+  {                                                                                                                    \
+    simgrid_add_plugin_description(#id, desc, init);                                                                   \
   }
 
 XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun);
   }
 
 XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun);