Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tesh: fix memory leaks.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 30 Nov 2011 22:28:52 +0000 (23:28 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 1 Dec 2011 07:40:17 +0000 (08:40 +0100)
tools/tesh/run_context.c
tools/tesh/tesh.c

index 1eaaedf..8a3fed4 100644 (file)
@@ -298,8 +298,10 @@ void rctx_pushline(const char *filepos, char kind, char *line)
 
     rctx->cmd = xbt_strdup(line);
     rctx->filepos = xbt_strdup(filepos);
-    if(option){
-       rctx->cmd = bprintf("%s %s",rctx->cmd,option);
+    if (option){
+      char *newcmd = bprintf("%s %s", rctx->cmd, option);
+      free(rctx->cmd);
+      rctx->cmd = newcmd;
     }
     XBT_INFO("[%s] %s%s", filepos, rctx->cmd,
           ((rctx->is_background) ? " (background command)" : ""));
@@ -560,7 +562,9 @@ void rctx_start(void)
   int child_out[2];
 
   XBT_DEBUG("Cmd before rewriting %s", rctx->cmd);
-  rctx->cmd = xbt_str_varsubst(rctx->cmd, env);
+  char *newcmd = xbt_str_varsubst(rctx->cmd, env);
+  free(rctx->cmd);
+  rctx->cmd = newcmd;
   XBT_VERB("Start %s %s", rctx->cmd,
         (rctx->is_background ? "(background job)" : ""));
   xbt_os_mutex_acquire(armageddon_mutex);
index f23c3be..7c1acc9 100644 (file)
@@ -245,10 +245,12 @@ int main(int argc, char *argv[])
             XBT_ERROR("--cfg argument requires an argument");
             exit(1);
       }
-      if(!option){ //if option is NULL
+      if (!option){ //if option is NULL
        option = bprintf("--cfg=%s",argv[i+1]);
-      }else{
-       option = bprintf("%s --cfg=%s",option,argv[i+1]);
+      } else {
+        char *newoption = bprintf("%s --cfg=%s", option, argv[i+1]);
+        free(option);
+        option = newoption;
       }
       XBT_INFO("Add option \'--cfg=%s\' to command line",argv[i+1]);
       memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *));
@@ -300,6 +302,6 @@ int main(int argc, char *argv[])
 
   rctx_exit();
   xbt_dict_free(&env);
-  xbt_free_f(option);
+  free(option);
   return 0;
 }