Bug 1150127 - Stop leaking windows via imgCacheValidator. r=baku, a=lizzard
authorSeth Fowler <mark.seth.fowler@gmail.com>
Tue, 07 Apr 2015 13:02:02 -0400
changeset 265509 6d6a22b769bd2783c71a289193f88f4207d09f85
parent 265508 58b5c2f98c1c5196cf3af2262f6db7a8e4c8c7bc
child 265510 0dcc817ca441b651e6512f0dd71c0d39d3c1c272
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku, lizzard
bugs1150127
milestone39.0a2
Bug 1150127 - Stop leaking windows via imgCacheValidator. r=baku, a=lizzard
image/src/imgLoader.cpp
--- a/image/src/imgLoader.cpp
+++ b/image/src/imgLoader.cpp
@@ -2617,16 +2617,19 @@ void imgCacheValidator::AddProxy(imgRequ
   mProxies.AppendObject(aProxy);
 }
 
 /** nsIRequestObserver methods **/
 
 /* void onStartRequest (in nsIRequest request, in nsISupports ctxt); */
 NS_IMETHODIMP imgCacheValidator::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt)
 {
+  // We may be holding on to a document, so ensure that it's released.
+  nsCOMPtr<nsISupports> context = mContext.forget();
+
   // If for some reason we don't still have an existing request (probably
   // because OnStartRequest got delivered more than once), just bail.
   if (!mRequest) {
     MOZ_ASSERT_UNREACHABLE("OnStartRequest delivered more than once?");
     aRequest->Cancel(NS_BINDING_ABORTED);
     return NS_ERROR_FAILURE;
   }
 
@@ -2665,17 +2668,17 @@ NS_IMETHODIMP imgCacheValidator::OnStart
         // Notify synchronously, because we're already in OnStartRequest, an
         // asynchronously-called function.
         proxy->SyncNotifyListener();
       }
 
       // We don't need to load this any more.
       aRequest->Cancel(NS_BINDING_ABORTED);
 
-      mRequest->SetLoadId(mContext);
+      mRequest->SetLoadId(context);
       mRequest->SetValidator(nullptr);
 
       mRequest = nullptr;
 
       mNewRequest = nullptr;
       mNewEntry = nullptr;
 
       return NS_OK;
@@ -2706,17 +2709,17 @@ NS_IMETHODIMP imgCacheValidator::OnStart
 
   mRequest->SetValidator(nullptr);
   mRequest = nullptr;
 
   // We use originalURI here to fulfil the imgIRequest contract on GetURI.
   nsCOMPtr<nsIURI> originalURI;
   channel->GetOriginalURI(getter_AddRefs(originalURI));
   mNewRequest->Init(originalURI, uri, mHadInsecureRedirect, aRequest, channel,
-                    mNewEntry, mContext, loadingPrincipal, corsmode, refpol);
+                    mNewEntry, context, loadingPrincipal, corsmode, refpol);
 
   mDestListener = new ProxyListener(mNewRequest);
 
   // Try to add the new request into the cache. Note that the entry must be in
   // the cache before the proxies' ownership changes, because adding a proxy
   // changes the caching behaviour for imgRequests.
   mImgLoader->PutIntoCache(originalURI, mNewEntry);
 
@@ -2735,16 +2738,19 @@ NS_IMETHODIMP imgCacheValidator::OnStart
   mNewEntry = nullptr;
 
   return mDestListener->OnStartRequest(aRequest, ctxt);
 }
 
 /* void onStopRequest (in nsIRequest request, in nsISupports ctxt, in nsresult status); */
 NS_IMETHODIMP imgCacheValidator::OnStopRequest(nsIRequest *aRequest, nsISupports *ctxt, nsresult status)
 {
+  // Be sure we've released the document that we may have been holding on to.
+  mContext = nullptr;
+
   if (!mDestListener)
     return NS_OK;
 
   return mDestListener->OnStopRequest(aRequest, ctxt, status);
 }
 
 /** nsIStreamListener methods **/