From 1c597e85ddb510ffeb4ee58441675b1b1c48737d Mon Sep 17 00:00:00 2001 From: thiery Date: Fri, 26 Nov 2010 14:18:58 +0000 Subject: [PATCH] Fix a memory leak in simix git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8672 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/simix/private.h | 4 ++++ src/simix/smx_global.c | 10 ++++++++++ src/simix/smx_network.c | 21 +++++---------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/simix/private.h b/src/simix/private.h index 568a9fc829..5915f97a3d 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -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; + 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; diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index c4a79957bd..1d958a53bf 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -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->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(); @@ -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->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); diff --git a/src/simix/smx_network.c b/src/simix/smx_network.c index 2c958a6aef..ab5a33f147 100644 --- a/src/simix/smx_network.c +++ b/src/simix/smx_network.c @@ -9,12 +9,6 @@ #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)"); @@ -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 - 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)); - 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 @@ -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; - 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", @@ -483,13 +474,11 @@ void SIMIX_network_copy_data(smx_comm_t comm) /* pimple to display the message sizes */ { - if (msg_sizes == NULL) - msg_sizes = xbt_dict_new(); casted_size = comm->task_size; - amount = xbt_dicti_get(msg_sizes, casted_size); + amount = xbt_dicti_get(simix_global->msg_sizes, casted_size); 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); - 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); -- 2.20.1