Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Chasing more leaks.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 10 Oct 2013 10:10:52 +0000 (12:10 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 10 Oct 2013 10:11:13 +0000 (12:11 +0200)
src/simix/smx_host.c
src/simix/smx_process.c

index a168ccf..2480bbd 100644 (file)
@@ -262,10 +262,14 @@ void* SIMIX_host_get_data(smx_host_t host){
 
   return SIMIX_host_priv(host)->data;
 }
-void _SIMIX_host_free_process_arg(void *);
-void _SIMIX_host_free_process_arg(void *data)
+
+static void _SIMIX_host_free_process_arg(void *data)
 {
   smx_process_arg_t arg = *(void**)data;
+  int i;
+  for (i = 0; i < arg->argc; i++)
+    xbt_free(arg->argv[i]);
+  xbt_free(arg->argv);
   xbt_free(arg->name);
   xbt_free(arg);
 }
@@ -323,9 +327,10 @@ void SIMIX_host_restart_processes(smx_host_t host)
   unsigned int cpt;
   smx_process_arg_t arg;
   xbt_dynar_t process_list = SIMIX_host_priv(host)->auto_restart_processes;
-  if(!process_list) return;
+  if (!process_list)
+    return;
 
-  xbt_dynar_foreach(process_list,cpt,arg) {
+  xbt_dynar_foreach (process_list, cpt, arg) {
 
     smx_process_t process;
 
@@ -341,20 +346,24 @@ void SIMIX_host_restart_processes(smx_host_t host)
                                             arg->argv,
                                             arg->properties,
                                             arg->auto_restart);
-    }
-    else {
+    } else {
       simcall_process_create(&process,
-                                            arg->argv[0],
-                                            arg->code,
-                                            NULL,
-                                            arg->hostname,
-                                            arg->kill_time,
-                                            arg->argc,
-                                            arg->argv,
-                                            arg->properties,
-                                            arg->auto_restart);
+                             arg->argv[0],
+                             arg->code,
+                             NULL,
+                             arg->hostname,
+                             arg->kill_time,
+                             arg->argc,
+                             arg->argv,
+                             arg->properties,
+                             arg->auto_restart);
 
     }
+    /* arg->argv is used by the process created above.  Hide it to
+     * _SIMIX_host_free_process_arg() which is called by xbt_dynar_reset()
+     * below. */
+    arg->argc = 0;
+    arg->argv = NULL;
   }
   xbt_dynar_reset(process_list);
 }
index e3bc046..bc5c087 100644 (file)
@@ -122,8 +122,8 @@ void SIMIX_process_empty_trash(void)
 
     xbt_dynar_free(&process->on_exit);
 
-    free(process->name);
-    free(process);
+    xbt_free(process->name);
+    xbt_free(process);
   }
 }
 
@@ -239,8 +239,12 @@ void SIMIX_process_create(smx_process_t *process,
   XBT_DEBUG("Start process %s on host '%s'", name, hostname);
 
   if (!SIMIX_host_get_state(host)) {
+    int i;
     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
           hostname);
+    for (i = 0; i < argc; i++)
+      xbt_free(argv[i]);
+    xbt_free(argv);
   }
   else {
     *process = xbt_new0(s_smx_process_t, 1);