Prevent use after free of ScriptEngine pointer when shutting down all scripts.

Before this change, if you were running with the Debug defaultScripts.js option on,
it could result in a dereference of a previously freed ScriptEngine pointer.
To prevent this, defaultScripts.js no longer explicitly calls ScriptDiscoveryService.stopScript() on
Script.scriptEnding.
This commit is contained in:
Anthony J. Thibault 2017-02-22 16:28:52 -08:00
parent de84e07281
commit 1429a32928

View file

@ -20,7 +20,7 @@ var DEFAULT_SCRIPTS = [
"system/bubble.js",
"system/snapshot.js",
"system/help.js",
"system/pal.js", //"system/mod.js", // older UX, if you prefer
"system/pal.js", // "system/mod.js", // older UX, if you prefer
"system/goto.js",
"system/marketplaces/marketplaces.js",
"system/edit.js",
@ -54,9 +54,6 @@ if (previousSetting === true || previousSetting === 'true') {
previousSetting = true;
}
if (Menu.menuExists(MENU_CATEGORY) && !Menu.menuItemExists(MENU_CATEGORY, MENU_ITEM)) {
Menu.addMenuItem({
menuName: MENU_CATEGORY,
@ -78,11 +75,11 @@ function runDefaultsSeparately() {
Script.load(DEFAULT_SCRIPTS[i]);
}
}
// start all scripts
if (Menu.isOptionChecked(MENU_ITEM)) {
// we're debugging individual default scripts
// so we load each into its own ScriptEngine instance
debuggingDefaultScripts = true;
runDefaultsSeparately();
} else {
// include all default scripts into this ScriptEngine
@ -90,32 +87,14 @@ if (Menu.isOptionChecked(MENU_ITEM)) {
}
function menuItemEvent(menuItem) {
if (menuItem == MENU_ITEM) {
isChecked = Menu.isOptionChecked(MENU_ITEM);
if (menuItem === MENU_ITEM) {
var isChecked = Menu.isOptionChecked(MENU_ITEM);
if (isChecked === true) {
Settings.setValue(SETTINGS_KEY, true);
} else if (isChecked === false) {
Settings.setValue(SETTINGS_KEY, false);
}
Window.alert('You must reload all scripts for this to take effect.')
}
}
function stopLoadedScripts() {
// remove debug script loads
var runningScripts = ScriptDiscoveryService.getRunning();
for (var i in runningScripts) {
var scriptName = runningScripts[i].name;
for (var j in DEFAULT_SCRIPTS) {
if (DEFAULT_SCRIPTS[j].slice(-scriptName.length) === scriptName) {
ScriptDiscoveryService.stopScript(runningScripts[i].url);
}
}
Window.alert('You must reload all scripts for this to take effect.');
}
}
@ -126,7 +105,6 @@ function removeMenuItem() {
}
Script.scriptEnding.connect(function() {
stopLoadedScripts();
removeMenuItem();
});