Bug 1333106 - Stop leaking in the prefetch service if the prefetch is blocked by security checks. r=mcmanus, a=jcristau
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 24 Jan 2017 10:02:46 -0500
changeset 377941 8c8965301d5cd1b10d46bdefad9cb2b49b169243
parent 377940 d72b6265473009f102359a293eb3a7c79c25eb96
child 377942 47e238a0c9e34e04d7c93cb3367e20c987f9af0d
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, jcristau
bugs1333106
milestone53.0a2
Bug 1333106 - Stop leaking in the prefetch service if the prefetch is blocked by security checks. r=mcmanus, a=jcristau
netwerk/protocol/http/nsHttpChannel.cpp
uriloader/prefetch/nsPrefetchService.cpp
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -5750,16 +5750,17 @@ nsHttpChannel::AsyncOpen(nsIStreamListen
     NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
 
     nsresult rv;
 
     MOZ_ASSERT(NS_IsMainThread());
 
     if (!gHttpHandler->Active()) {
         LOG(("  after HTTP shutdown..."));
+        ReleaseListeners();
         return NS_ERROR_NOT_AVAILABLE;
     }
 
     rv = NS_CheckPortSafety(mURI);
     if (NS_FAILED(rv)) {
         ReleaseListeners();
         return rv;
     }
@@ -5828,17 +5829,20 @@ nsHttpChannel::AsyncOpen(nsIStreamListen
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHttpChannel::AsyncOpen2(nsIStreamListener *aListener)
 {
   nsCOMPtr<nsIStreamListener> listener = aListener;
   nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+      ReleaseListeners();
+      return rv;
+  }
   return AsyncOpen(listener, nullptr);
 }
 
 // BeginConnect() SHOULD NOT call AsyncAbort(). AsyncAbort will be called by
 // functions that called BeginConnect if needed. Only AsyncOpen and
 // OnProxyAvailable ever call BeginConnect.
 nsresult
 nsHttpChannel::BeginConnect()
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -151,17 +151,23 @@ nsPrefetchNode::OpenChannel()
     if (httpChannel) {
         httpChannel->SetReferrerWithPolicy(mReferrerURI, referrerPolicy);
         httpChannel->SetRequestHeader(
             NS_LITERAL_CSTRING("X-Moz"),
             NS_LITERAL_CSTRING("prefetch"),
             false);
     }
 
-    return mChannel->AsyncOpen2(this);
+    rv = mChannel->AsyncOpen2(this);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      // Drop the ref to the channel, because we don't want to end up with
+      // cycles through it.
+      mChannel = nullptr;
+    }
+    return rv;
 }
 
 nsresult
 nsPrefetchNode::CancelChannel(nsresult error)
 {
     mChannel->Cancel(error);
     mChannel = nullptr;