[mw-devel] MW3 r951 - trunk/src

psycodom at sucs.org psycodom at sucs.org
Sat Apr 21 16:45:32 BST 2007


Author: psycodom
Date: 2007-04-21 16:45:32 +0100 (Sat, 21 Apr 2007)
New Revision: 951

Modified:
   trunk/src/js.c
Log:
Fixes javascript invalid pointer free() issue on GC

Modified: trunk/src/js.c
===================================================================
--- trunk/src/js.c	2007-04-21 15:29:59 UTC (rev 950)
+++ trunk/src/js.c	2007-04-21 15:45:32 UTC (rev 951)
@@ -504,9 +504,9 @@
 		//	js_string = local2jschars(argvc[i]);
 			if (js_string != NULL) {
 		//		argv[i] = STRING_TO_JSVAL(JS_NewUCString(jscx, js_string, strlen(argvc[i])));
-				argv[i] = STRING_TO_JSVAL(JS_NewString(jscx, argvc[i], strlen(argvc[i])));
+				argv[i] = STRING_TO_JSVAL(JS_NewStringCopyZ(jscx, argvc[i]));
 			} else {
-				argv[i] = STRING_TO_JSVAL(JS_NewString(jscx, "(Garbled string)", 16));
+				argv[i] = STRING_TO_JSVAL(JS_NewStringCopyZ(jscx, "(Garbled string)"));
 			}
 		if (js_string) JS_free(jscx, js_string);
 	}
@@ -520,7 +520,7 @@
 		script_output=0;
 	}
 	free(argv);
-	JS_GC(jscx);
+	JS_GC(jscx); // do we still need to do this now the actual bug has been found?
 	return ret ? 1 : 0;
 }
 
@@ -694,10 +694,10 @@
 	}
 
 	/* need additional functions : 
-	 * - one to bind functions to events (bind?)
-	 * - one to load another script (include?)
-	 * - get system date/time
-	 * - input line of text (does anyone use this)
+	 * - one to bind functions to events (bind?) - yes, saves needing two files per javascript.  code written outside of a function is executed when the script loads
+	 * - one to load another script (include?) - possibly although most scripts are loaded from the .mwrc or using .load
+	 * - get system date/time - no, 'new Date()' will get this information for you in a Date object.
+	 * - input line of text (does anyone use this) - yes, it's nice to be able to prompt the user for extra information.  I specifically use it in my batchdo mwscript that allows me to specify a set of commands to do at once.
 	 */
 
 	return 0;





More information about the mw-devel mailing list