Bug 1442925 - Fix leak caused by XBL in toolbarless popups. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sun, 11 Mar 2018 14:40:33 +0100
changeset 31268 3736b11f0775e88791490969d0fc734816fd8aac
parent 31267 3d883f9f14a9898be052f305df7d66de218e095b
child 31269 1cb55e399e917d4f48c2f73a001cd6d1653670f5
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersIanN
bugs1442925, 1106432
Bug 1442925 - Fix leak caused by XBL in toolbarless popups. r=IanN Port part of Bug 1106432 to SeaMonkey.
suite/common/search/search.xml
--- a/suite/common/search/search.xml
+++ b/suite/common/search/search.xml
@@ -90,22 +90,26 @@
           var os = Cc["@mozilla.org/observer-service;1"]
                      .getService(Ci.nsIObserverService);
           os.removeObserver(this, "browser-search-engine-modified");
           this._addedObserver = false;
         }
 
         // Make sure to break the cycle from _textbox to us. Otherwise we leak
         // the world. But make sure it's actually pointing to us.
-        if (this._textbox.mController.input == this)
+        // Also make sure the textbox has ever been constructed, otherwise the
+        // _textbox getter will cause the textbox constructor to run, add an
+        // observer, and leak the world too.
+        if (this._textboxInitialized && this._textbox.mController.input == this)
           this._textbox.mController.input = null;
       ]]></destructor>
 
       <field name="_stringBundle">document.getAnonymousElementByAttribute(this,
           "anonid", "searchbar-stringbundle");</field>
+      <field name="_textboxInitialized">false</field>
       <field name="_textbox">document.getAnonymousElementByAttribute(this,
           "anonid", "searchbar-textbox");</field>
       <field name="_popup">document.getAnonymousElementByAttribute(this,
           "anonid", "searchbar-popup");</field>
       <field name="searchButton">document.getAnonymousElementByAttribute(this,
           "anonid", "searchbar-engine-button");</field>
       <field name="_searchService">
         Components.classes["@mozilla.org/browser/search-service;1"]
@@ -523,16 +527,17 @@
             "toolbarpaletteitem")
           return;
 
         if (this._prefBranch.getBoolPref("browser.urlbar.clickSelectsAll"))
           this.setAttribute("clickSelectsAll", true);
 
         // Add items to context menu and attach controller to handle them
         this.controllers.appendController(this.searchbarController);
+        document.getBindingParent(this)._textboxInitialized = true;
 
         // Add observer for suggest preference
         this._prefBranch.addObserver("browser.search.suggest.enabled", this);
 
         this._inputBox.setAttribute("suggestchecked", this._suggestEnabled);
 
         ChromeUtils.import("resource://gre/modules/FormHistory.jsm", this);
       ]]></constructor>