From 18f67f374327c174d04fa0856f2d23f77c8b8615 Mon Sep 17 00:00:00 2001 From: JustOff Date: Fri, 10 Nov 2017 22:17:10 +0200 Subject: [PATCH] Prevent potential memory leaks --- bootstrap.js | 12 ++++++++++++ content/ca-archive.js | 18 +++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 1484366..848b759 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -11,6 +11,16 @@ const CAA_URI = Services.io.newURI(CAA_URL, null, null); const nsIURI = CC("@mozilla.org/network/simple-uri;1", "nsIURI"); +const CAA_MODULES = [ + "chrome://ca-archive/content/about.js", + "chrome://ca-archive/content/addon.js", + "chrome://ca-archive/content/db.js", + "chrome://ca-archive/content/epl.js", + "chrome://ca-archive/content/list.js", + "chrome://ca-archive/content/tcloud.js", + "chrome://ca-archive/content/versions.js" +]; + let factory, gWindowListener = null, branch = "extensions.ca-archive."; let styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService); @@ -292,6 +302,8 @@ function shutdown(data, reason) { if (styleSheetService.sheetRegistered(styleSheetURI, styleSheetService.USER_SHEET)) { styleSheetService.unregisterSheet(styleSheetURI, styleSheetService.USER_SHEET); } + + CAA_MODULES.forEach(Cu.unload, Cu); } function install(data, reason) {} diff --git a/content/ca-archive.js b/content/ca-archive.js index 7fdca8c..3a05992 100644 --- a/content/ca-archive.js +++ b/content/ca-archive.js @@ -2,9 +2,9 @@ (function () { var Cu = Components.utils; - let dbname = "ca-archive-17110901.sqlite"; let ver = "17110902"; + let dbname = "ca-archive-17110901.sqlite"; - Cu.import("chrome://ca-archive/content/db.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/db.js"); if (!DB.openDB(dbname, document)) { return; } @@ -20,25 +20,25 @@ try { let params, url = decodeURI(document.location); if ((params = /^caa:addon\/(.+?)\/versions\/?(\?page=(\d+)(#.+)?)?$/.exec(url)) !== null) { - Cu.import("chrome://ca-archive/content/versions.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/versions.js"); Versions.showPage(document, DB.db, params[1], params[3]); } else if ((params = /^caa:addon\/(.+?)\/(eula|privacy|license\/(.+))$/.exec(url)) !== null) { - Cu.import("chrome://ca-archive/content/epl.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/epl.js"); EPL.showPage(document, DB.db, params[1], params[2], params[3]); } else if ((params = /^caa:addon\/(.+?)\/?$/.exec(url)) !== null) { - Cu.import("chrome://ca-archive/content/addon.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/addon.js"); Addon.showPage(document, DB.db, params[1]); } else if ((params = /^caa:list(\/([a-z-]+))?(\?tag=(.+?)|\?q=(.+?))?([\?|\&]sort=(\w+))?\&?(page=(\d+))?$/.exec(url)) !== null) { - Cu.import("chrome://ca-archive/content/list.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/list.js"); List.showPage(document, DB.db, params[2], params[4], params[5], params[7], params[9]); } else if (url == "caa:") { - Cu.import("chrome://ca-archive/content/tcloud.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/tcloud.js"); TCloud.showPage(document, DB.db); } else if (url == "caa:about") { - Cu.import("chrome://ca-archive/content/about.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/about.js"); About.showPage(document, DB.db); } else if ((params = /^caa:(.+)$/.exec(url)) !== null) { - Cu.import("chrome://ca-archive/content/list.js" + "?" + ver); + Cu.import("chrome://ca-archive/content/list.js"); List.showPage(document, DB.db, undefined, undefined, params[1], undefined, undefined); } else { document.location = "caa:list";