Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a memory leak in simix
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Nov 2010 14:18:58 +0000 (14:18 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Nov 2010 14:18:58 +0000 (14:18 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8672 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/simix/private.h
src/simix/smx_global.c
src/simix/smx_network.c

index 568a9fc..5915f97 100644 (file)
@@ -47,6 +47,10 @@ typedef struct SIMIX_Global {
   smx_creation_func_t create_process_function;
   void_f_pvoid_t kill_process_function;
   void_f_pvoid_t cleanup_process_function;
   smx_creation_func_t create_process_function;
   void_f_pvoid_t kill_process_function;
   void_f_pvoid_t cleanup_process_function;
+  xbt_dict_t msg_sizes; /* pimple to get an histogram of message sizes in the simulation */
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  xbt_dict_t latency_limited_dict;
+#endif
 } s_SIMIX_Global_t, *SIMIX_Global_t;
 
 extern SIMIX_Global_t simix_global;
 } s_SIMIX_Global_t, *SIMIX_Global_t;
 
 extern SIMIX_Global_t simix_global;
index c4a7995..1d958a5 100644 (file)
@@ -74,6 +74,11 @@ void SIMIX_global_init(int *argc, char **argv)
     simix_global->kill_process_function = NULL;
     simix_global->cleanup_process_function = SIMIX_process_cleanup;
 
     simix_global->kill_process_function = NULL;
     simix_global->cleanup_process_function = SIMIX_process_cleanup;
 
+    simix_global->msg_sizes = xbt_dict_new();
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+    simix_global->latency_limited_dict = xbt_dict_new();
+#endif
+
     SIMIX_context_mod_init();
     SIMIX_create_maestro_process();
 
     SIMIX_context_mod_init();
     SIMIX_create_maestro_process();
 
@@ -262,6 +267,11 @@ void SIMIX_clean(void)
   xbt_dict_free(&(simix_global->registered_functions));
   xbt_dict_free(&(simix_global->host));
 
   xbt_dict_free(&(simix_global->registered_functions));
   xbt_dict_free(&(simix_global->host));
 
+  xbt_dict_free(&(simix_global->msg_sizes));
+#ifdef HAVE_LATENCY_BOUND_TRACKING
+  xbt_dict_free(&(simix_global->latency_limited_dict));
+#endif
+
   /* Let's free maestro now */
   SIMIX_context_free(simix_global->maestro_process->context);
   xbt_free(simix_global->maestro_process->exception);
   /* Let's free maestro now */
   SIMIX_context_free(simix_global->maestro_process->context);
   xbt_free(simix_global->maestro_process->exception);
index 2c958a6..ab5a33f 100644 (file)
@@ -9,12 +9,6 @@
 #include "mc/mc.h"
 #include "xbt/dict.h"
 
 #include "mc/mc.h"
 #include "xbt/dict.h"
 
-/* Pimple to get an histogram of message sizes in the simulation */
-xbt_dict_t msg_sizes = NULL;
-#ifdef HAVE_LATENCY_BOUND_TRACKING
-xbt_dict_t latency_limited_dict = NULL;
-#endif
-
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix,
                                 "Logging specific to SIMIX (network)");
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix,
                                 "Logging specific to SIMIX (network)");
 
@@ -176,13 +170,10 @@ void SIMIX_communication_destroy(smx_comm_t comm)
 
 #ifdef HAVE_LATENCY_BOUND_TRACKING
   //save is latency limited flag to use afterwards
 
 #ifdef HAVE_LATENCY_BOUND_TRACKING
   //save is latency limited flag to use afterwards
-  if (latency_limited_dict == NULL) {
-    latency_limited_dict = xbt_dict_new();
-  }
   if (comm->act) {
     DEBUG2("adding key %p with latency limited value %d to the dict", comm,
            SIMIX_action_is_latency_bounded(comm->act));
   if (comm->act) {
     DEBUG2("adding key %p with latency limited value %d to the dict", comm,
            SIMIX_action_is_latency_bounded(comm->act));
-    xbt_dicti_set(latency_limited_dict, (uintptr_t) comm,
+    xbt_dicti_set(simix_global->latency_limited_dict, (uintptr_t) comm,
                   SIMIX_action_is_latency_bounded(comm->act));
   }
 #endif
                   SIMIX_action_is_latency_bounded(comm->act));
   }
 #endif
@@ -409,7 +400,7 @@ XBT_INLINE int SIMIX_communication_is_latency_bounded(smx_comm_t comm)
   uintptr_t key = 0;
   uintptr_t data = 0;
   xbt_dict_cursor_t cursor;
   uintptr_t key = 0;
   uintptr_t data = 0;
   xbt_dict_cursor_t cursor;
-  xbt_dict_foreach(latency_limited_dict, cursor, key, data) {
+  xbt_dict_foreach(simix_global->latency_limited_dict, cursor, key, data) {
     DEBUG2("comparing key=%p with comm=%p", (void *) key, (void *) comm);
     if ((void *) comm == (void *) key) {
       DEBUG2("key %p found, return value latency limited value %d",
     DEBUG2("comparing key=%p with comm=%p", (void *) key, (void *) comm);
     if ((void *) comm == (void *) key) {
       DEBUG2("key %p found, return value latency limited value %d",
@@ -483,13 +474,11 @@ void SIMIX_network_copy_data(smx_comm_t comm)
 
   /* pimple to display the message sizes */
   {
 
   /* pimple to display the message sizes */
   {
-    if (msg_sizes == NULL)
-      msg_sizes = xbt_dict_new();
     casted_size = comm->task_size;
     casted_size = comm->task_size;
-    amount = xbt_dicti_get(msg_sizes, casted_size);
+    amount = xbt_dicti_get(simix_global->msg_sizes, casted_size);
     amount++;
 
     amount++;
 
-    xbt_dicti_set(msg_sizes, casted_size, amount);
+    xbt_dicti_set(simix_global->msg_sizes, casted_size, amount);
   }
 }
 
   }
 }
 
@@ -504,7 +493,7 @@ void SIMIX_message_sizes_output(const char *filename)
   out = fopen(filename, "w");
   xbt_assert1(out, "Cannot open file %s", filename);
 
   out = fopen(filename, "w");
   xbt_assert1(out, "Cannot open file %s", filename);
 
-  xbt_dict_foreach(msg_sizes, cursor, key, data) {
+  xbt_dict_foreach(simix_global->msg_sizes, cursor, key, data) {
     fprintf(out, "%zu %zu\n", key, data);
   }
   fclose(out);
     fprintf(out, "%zu %zu\n", key, data);
   }
   fclose(out);