Bug 1525729 - Avoid memory leak via AddonTestUtils.initMochiTest r=aswan
authorRob Wu <rob@robwu.nl>
Thu, 14 Mar 2019 16:28:20 +0000
changeset 521910 e9f1a449031d
parent 521909 e10b87be35ad
child 521911 9071e6d7836b
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1525729
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525729 - Avoid memory leak via AddonTestUtils.initMochiTest r=aswan When I added AddonTestUtils.initMochiTest to an existing test at browser/components/preferences/in-content/tests/browser_extension_controlled.js , the test started to fail often on debug builds, with errors like "leaked 2 window(s) until shutdown". Fix this by clearing the global that was saved by initMochiTest. Differential Revision: https://phabricator.services.mozilla.com/D23502
toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
--- a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
@@ -410,16 +410,20 @@ var AddonTestUtils = {
 
     this.profileExtensions = FileUtils.getDir("ProfD", ["extensions"]);
 
     this.tempDir = FileUtils.getDir("TmpD", []);
     this.tempDir.append("addons-mochitest");
     this.tempDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
 
     testScope.registerCleanupFunction(() => {
+      // Defer testScope cleanup until the last cleanup function has run.
+      testScope.registerCleanupFunction(() => {
+        this.testScope = null;
+      });
       this.cleanupTempXPIs();
       try {
         this.tempDir.remove(true);
       } catch (e) {
         Cu.reportError(e);
       }
     });
   },