aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2011-12-01 17:29:09 +1000
committerSteve Bennett <steveb@workware.net.au>2011-12-01 17:35:17 +1000
commit666f15ffdee6bcb6b8b481f54c501ed6058cd7fc (patch)
treedc6d9e001c620256494b91d45ba40b01e86b4055 /jim-exec.c
parent22e58536526f37a2da781960fb3f92988986f092 (diff)
downloadjimtcl-666f15ffdee6bcb6b8b481f54c501ed6058cd7fc.zip
jimtcl-666f15ffdee6bcb6b8b481f54c501ed6058cd7fc.tar.gz
jimtcl-666f15ffdee6bcb6b8b481f54c501ed6058cd7fc.tar.bz2
Ref count fix in exec
Passing a zero refcount object to Jim_AioFilename() is a bad idea. If the implementation changes, the object may be freed twice. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-exec.c')
-rw-r--r--jim-exec.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/jim-exec.c b/jim-exec.c
index f60bdef..6008490 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -552,6 +552,19 @@ static void JimDetachPids(Jim_Interp *interp, int numPids, const pidtype *pidPtr
}
}
+static FILE *JimGetAioFilehandle(Jim_Interp *interp, const char *name)
+{
+ FILE *fh;
+ Jim_Obj *fhObj;
+
+ fhObj = Jim_NewStringObj(interp, name, -1);
+ Jim_IncrRefCount(fhObj);
+ fh = Jim_AioFilehandle(interp, fhObj);
+ Jim_DecrRefCount(interp, fhObj);
+
+ return fh;
+}
+
/*
*----------------------------------------------------------------------
*
@@ -778,10 +791,8 @@ badargs:
}
else if (inputFile == FILE_HANDLE) {
/* Should be a file descriptor */
- Jim_Obj *fhObj = Jim_NewStringObj(interp, input, -1);
- FILE *fh = Jim_AioFilehandle(interp, fhObj);
+ FILE *fh = JimGetAioFilehandle(interp, input);
- Jim_FreeNewObj(interp, fhObj);
if (fh == NULL) {
goto error;
}
@@ -814,10 +825,7 @@ badargs:
*/
if (output != NULL) {
if (outputFile == FILE_HANDLE) {
- Jim_Obj *fhObj = Jim_NewStringObj(interp, output, -1);
- FILE *fh = Jim_AioFilehandle(interp, fhObj);
-
- Jim_FreeNewObj(interp, fhObj);
+ FILE *fh = JimGetAioFilehandle(interp, output);
if (fh == NULL) {
goto error;
}
@@ -861,10 +869,7 @@ badargs:
}
}
if (errorId == JIM_BAD_FD) {
- Jim_Obj *fhObj = Jim_NewStringObj(interp, error, -1);
- FILE *fh = Jim_AioFilehandle(interp, fhObj);
-
- Jim_FreeNewObj(interp, fhObj);
+ FILE *fh = JimGetAioFilehandle(interp, error);
if (fh == NULL) {
goto error;
}