shithub: libmujs

Download patch

ref: ac9de3c67bc6c8985c1a417c3fde76f4ce7db515
parent: 5d1904912cd96b632b2185a69fada13a27226a06
author: Tor Andersson <tor.andersson@artifex.com>
date: Tue Sep 26 10:37:56 EDT 2017

Fix memory leak in main.

--- a/main.c
+++ b/main.c
@@ -181,7 +181,7 @@
 {
 	char line[256];
 	js_State *J;
-	int i;
+	int i, status = 0;
 
 	J = js_newstate(NULL, NULL, JS_STRICT);
 
@@ -210,11 +210,9 @@
 	js_dostring(J, stacktrace_js);
 
 	if (argc > 1) {
-		for (i = 1; i < argc; ++i) {
+		for (i = 1; i < argc; ++i)
 			if (js_dofile(J, argv[i]))
-				return 1;
-			js_gc(J, 0);
-		}
+				status = 1;
 	} else {
 		if (isatty(0)) {
 			fputs(PS1, stdout);
@@ -223,19 +221,16 @@
 				fputs(PS1, stdout);
 			}
 			putchar('\n');
-			js_gc(J, 1);
 		} else {
 			char *input = read_stdin();
-			if (!input)
-				return 1;
-			if (js_dostring(J, input))
-				return 1;
+			if (!input || !js_dostring(J, input))
+				status = 1;
 			free(input);
-			js_gc(J, 0);
 		}
 	}
 
+	js_gc(J, 0);
 	js_freestate(J);
 
-	return 0;
+	return status;
 }