Bug 446689 - xpcshell's load() function doesn't close file handle; r+sr=mrbkap
authorAiko <Seno.Aiko@live.com>
Sun, 15 Feb 2009 17:23:50 +0100
changeset 25000 0a341c0bfc3ff04001835cbebfb42578bed86092
parent 24999 bd35ca5e194ab9680e3d82dea7d2328694438da9
child 25001 252b7dc440db34abb1c0efae2fd778b0d9ac2774
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs446689
milestone1.9.2a1pre
Bug 446689 - xpcshell's load() function doesn't close file handle; r+sr=mrbkap
js/src/xpconnect/shell/xpcshell.cpp
--- a/js/src/xpconnect/shell/xpcshell.cpp
+++ b/js/src/xpconnect/shell/xpcshell.cpp
@@ -444,16 +444,18 @@ Load(JSContext *cx, JSObject *obj, uintN
         str = JS_ValueToString(cx, argv[i]);
         if (!str)
             return JS_FALSE;
         argv[i] = STRING_TO_JSVAL(str);
         filename = JS_GetStringBytes(str);
         file = fopen(filename, "r");
         script = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,
                                                    gJSPrincipals);
+        if (file)
+            fclose(file);
         if (!script)
             ok = JS_FALSE;
         else {
             ok = !compileOnly
                  ? JS_ExecuteScript(cx, obj, script, &result)
                  : JS_TRUE;
             JS_DestroyScript(cx, script);
         }
@@ -930,16 +932,18 @@ Process(JSContext *cx, JSObject *obj, co
                                  JSSMSG_CANT_OPEN,
                                  filename, strerror(errno));
             gExitCode = EXITCODE_FILE_NOT_FOUND;
             return;
         }
     }
 
     ProcessFile(cx, obj, filename, file, forceTTY);
+    if (file != stdin)
+        fclose(file);
 }
 
 static int
 usage(void)
 {
     fprintf(gErrFile, "%s\n", JS_GetImplementationVersion());
     fprintf(gErrFile, "usage: xpcshell [-g gredir] [-PswWxCij] [-v version] [-f scriptfile] [-e script] [scriptfile] [scriptarg...]\n");
     return 2;
@@ -957,16 +961,17 @@ ProcessArgs(JSContext *cx, JSObject *obj
     char *filename = NULL;
     JSBool isInteractive = JS_TRUE;
     JSBool forceTTY = JS_FALSE;
 
     rcfile = fopen(rcfilename, "r");
     if (rcfile) {
         printf("[loading '%s'...]\n", rcfilename);
         ProcessFile(cx, obj, rcfilename, rcfile, JS_FALSE);
+        fclose(rcfile);
     }
 
     /*
      * Scan past all optional arguments so we can create the arguments object
      * before processing any -f options, which must interleave properly with
      * -v and -w options.  This requires two passes, and without getopt, we'll
      * have to keep the option logic here and in the second for loop in sync.
      */