Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memory leak
authornavarro <navarro@caraja.(none)>
Tue, 31 Jul 2012 15:42:16 +0000 (17:42 +0200)
committernavarro <navarro@caraja.(none)>
Tue, 31 Jul 2012 15:44:01 +0000 (17:44 +0200)
examples/msg/io/file.c
include/msg/msg.h
src/msg/msg_io.c
src/simix/smx_io.c
src/surf/storage.c

index cdcf901..6769661 100644 (file)
@@ -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);
index 192c44f..2d62058 100644 (file)
@@ -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 ***********************************/
index 3774f1e..7d51d15 100644 (file)
@@ -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);
+}
index 33424c6..31aa2f6 100644 (file)
@@ -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;
index ace5d0a..2e868d7 100644 (file)
@@ -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);
 }