Bug 1400562 - BackgroundPageThumbs.captureIfMissing leaks when hidden capturing_disabled pref is true draft
authorUrsula Sarracini
Tue, 10 Oct 2017 13:22:54 -0400
changeset 678043 cb5249929a6801c568c60f4dd0d3929c66328a8c
parent 677214 77a4c52e9987d2359969d7c478183b438b464744
child 735219 63c78ae61ce698d2f11c8de6508c4b1835fd7faa
push id83806
push userusarracini@mozilla.com
push dateTue, 10 Oct 2017 19:21:26 +0000
bugs1400562
milestone58.0a1
Bug 1400562 - BackgroundPageThumbs.captureIfMissing leaks when hidden capturing_disabled pref is true MozReview-Commit-ID: 6zb3uBCYTk5
toolkit/components/thumbnails/BackgroundPageThumbs.jsm
--- a/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
+++ b/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
@@ -100,16 +100,23 @@ const BackgroundPageThumbs = {
    * @param url      The URL to capture.
    * @param options  An optional object that configures the capture.  See
    *                 capture() for description.
    *   unloadingPromise This option is resolved when the calling context is
    *                    unloading, so things can be cleaned up to avoid leak.
    * @return {Promise} A Promise that resolves when this task completes
    */
   async captureIfMissing(url, options = {}) {
+    // Short circuit this function if pref is enabled, or else we leak observers.
+    // See Bug 1400562
+    if (!PageThumbs._prefEnabled()) {
+      if (options.onDone)
+        options.onDone(url);
+      return url;
+    }
     // The fileExistsForURL call is an optimization, potentially but unlikely
     // incorrect, and no big deal when it is.  After the capture is done, we
     // atomically test whether the file exists before writing it.
     let exists = await PageThumbsStorage.fileExistsForURL(url);
     if (exists) {
       if (options.onDone) {
         options.onDone(url);
       }