diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-05-18 17:19:51 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-05-18 17:19:51 +1000 |
commit | 391fe26d1f8a6965b404c21e9d64c2e41cab3767 (patch) | |
tree | b3814df3773ed2251d3f7ab056aac08e172ab0d1 /jim-exec.c | |
parent | 5cf719de9816bb8415c2e87e82f46d3084041778 (diff) | |
download | jimtcl-391fe26d1f8a6965b404c21e9d64c2e41cab3767.zip jimtcl-391fe26d1f8a6965b404c21e9d64c2e41cab3767.tar.gz jimtcl-391fe26d1f8a6965b404c21e9d64c2e41cab3767.tar.bz2 |
Fix memory leak on exec argument error
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-exec.c')
-rw-r--r-- | jim-exec.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -597,10 +597,6 @@ Jim_CreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int **pid } pipeIds[0] = pipeIds[1] = -1; - /* Must do this before vfork(), so do it now */ - orig_environ = environ; - environ = JimBuildEnv(interp); - /* * First, scan through all the arguments to figure out the structure * of the pipeline. Count the number of distinct processes (it's the @@ -676,8 +672,7 @@ Jim_CreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int **pid if (strcmp(arg, "|") == 0 || strcmp(arg, "|&") == 0) { if (i == lastBar + 1 || i == argc - 1) { Jim_SetResultString(interp, "illegal use of | or |& in command", -1); - Jim_Free(arg_array); - return -1; + goto badargs; } lastBar = i; cmdCount++; @@ -689,17 +684,21 @@ Jim_CreatePipeline(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int **pid if (i >= argc) { Jim_SetResultFormatted(interp, "can't specify \"%s\" as last word in command", arg); - Jim_Free(arg_array); - return -1; + goto badargs; } } if (arg_count == 0) { Jim_SetResultString(interp, "didn't specify command to execute", -1); +badargs: Jim_Free(arg_array); return -1; } + /* Must do this before vfork(), so do it now */ + orig_environ = environ; + environ = JimBuildEnv(interp); + /* * Set up the redirected input source for the pipeline, if * so requested. |