aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2011-05-18 17:19:51 +1000
committerSteve Bennett <steveb@workware.net.au>2011-05-18 17:19:51 +1000
commit391fe26d1f8a6965b404c21e9d64c2e41cab3767 (patch)
treeb3814df3773ed2251d3f7ab056aac08e172ab0d1 /jim-exec.c
parent5cf719de9816bb8415c2e87e82f46d3084041778 (diff)
downloadjimtcl-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.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/jim-exec.c b/jim-exec.c
index 30d2266..52e0c17 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -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.