Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tesh: fix memory leaks.
[simgrid.git] / tools / tesh / run_context.c
index fcf6d3c..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);
@@ -653,7 +657,7 @@ static int cmpstringp(const void *p1, const void *p2) {
 
   int res = strncmp(s1, s2, sort_len);
   if (res == 0)
-    return p1>p2;
+    res = p1 > p2 ? 1 : (p1 < p2 ? -1 : 0);
   return res;
 }