From: navarro Date: Tue, 31 Jul 2012 15:42:16 +0000 (+0200) Subject: Fix memory leak X-Git-Tag: v3_8~245 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3caf6372b036a72110757e43456d08e0a463e7d3?hp=b19b4ec8e7ea6fbccc30d4e18ef5a5c16e44e251 Fix memory leak --- diff --git a/examples/msg/io/file.c b/examples/msg/io/file.c index cdcf90116d..67696610e2 100644 --- a/examples/msg/io/file.c +++ b/examples/msg/io/file.c @@ -61,6 +61,7 @@ int host(int argc, char *argv[]) MSG_file_stat(file,&stat); XBT_INFO("\tFile stat %s Size %.1f",file->name,stat.size); + MSG_file_free_stat(&stat); XBT_INFO("\tClose file '%s'",file->name); MSG_file_close(file); diff --git a/include/msg/msg.h b/include/msg/msg.h index 192c44faba..2d62058829 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -77,6 +77,7 @@ XBT_PUBLIC(size_t) MSG_file_write(const void* ptr, size_t size, size_t nmemb, ms XBT_PUBLIC(msg_file_t) MSG_file_open(const char* mount, const char* path, const char* mode); XBT_PUBLIC(int) MSG_file_close(msg_file_t fp); XBT_PUBLIC(int) MSG_file_stat(msg_file_t fd, s_msg_stat_t *buf); +XBT_PUBLIC(void) MSG_file_free_stat(s_msg_stat_t *stat); /************************** Host handling ***********************************/ diff --git a/src/msg/msg_io.c b/src/msg/msg_io.c index 3774f1eb1a..7d51d15d75 100644 --- a/src/msg/msg_io.c +++ b/src/msg/msg_io.c @@ -81,7 +81,11 @@ msg_file_t MSG_file_open(const char* mount, const char* path, const char* mode) */ int MSG_file_close(msg_file_t fp) { - return simcall_file_close(fp->simdata->smx_file); + int res = simcall_file_close(fp->simdata->smx_file); + free(fp->name); + xbt_free(fp->simdata); + xbt_free(fp); + return res; } /** \ingroup msg_file_management @@ -97,3 +101,17 @@ int MSG_file_stat(msg_file_t fd, s_msg_stat_t *buf) res = simcall_file_stat(fd->simdata->smx_file, buf); return res; } + +/** \ingroup msg_file_management + * \brief Free the stat structure + * + * \param stat the #s_msg_stat_t to free + */ +void MSG_file_free_stat(s_msg_stat_t *stat) +{ + free(stat->date); + free(stat->group); + free(stat->time); + free(stat->user); + free(stat->user_rights); +} diff --git a/src/simix/smx_io.c b/src/simix/smx_io.c index 33424c6ba8..31aa2f6c71 100644 --- a/src/simix/smx_io.c +++ b/src/simix/smx_io.c @@ -219,7 +219,8 @@ void SIMIX_post_io(smx_action_t action) simcall->file_open.result->surf_file = (action->io.surf_io)->file; break; case SIMCALL_FILE_CLOSE: - simcall->file_read.result = 0; + xbt_free(simcall->file_close.fp); + simcall->file_close.result = 0; break; case SIMCALL_FILE_WRITE: simcall->file_write.result = (action->io.surf_io)->cost; diff --git a/src/surf/storage.c b/src/surf/storage.c index ace5d0af45..2e868d7c7e 100644 --- a/src/surf/storage.c +++ b/src/surf/storage.c @@ -189,7 +189,7 @@ static void* storage_create_resource(const char* id, const char* model,const cha storage_type->properties, Bread); - if(!storage_list) storage_list=xbt_dynar_new(sizeof(char *),free); + if(!storage_list) storage_list=xbt_dynar_new(sizeof(char *),NULL); xbt_dynar_push(storage_list,&storage); return storage; @@ -203,6 +203,9 @@ static void storage_finalize(void) surf_model_exit(surf_storage_model); surf_storage_model = NULL; + if(storage_list) + xbt_dynar_free(&storage_list); + xbt_swag_free (storage_running_action_set_that_does_not_need_being_checked); storage_running_action_set_that_does_not_need_being_checked = NULL; @@ -620,6 +623,7 @@ static XBT_INLINE void surf_storage_resource_free(void *r) // specific to storage storage_t storage = r; xbt_dict_free(&storage->content); + xbt_dynar_free(&storage->write_actions); // generic resource surf_resource_free(r); }