Bug 1512472 - Hold nsHttpConnectionInfo in a RefPtr to avoid leak when returning early r=dragana a=pascalc
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 19 Mar 2019 12:03:23 +0000
changeset 525812 3b2fad2fe236ef5607b2dba3cb5fb360b1197af1
parent 525811 111a68271a2dfc91a27d30a1496024728ebaa5ce
child 525813 98acf3216e5a3445f7da68960fa51a1f53e65163
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, pascalc
bugs1512472
milestone67.0
Bug 1512472 - Hold nsHttpConnectionInfo in a RefPtr to avoid leak when returning early r=dragana a=pascalc nsHttpConnectionMgr::SpeculativeConnect may return early, without assigning ci to a RefPtr. In that case, we'd leak the nsHttpConnectionInfo. We need to have it in a RefPtr from the start to make sure we can't leak it. Differential Revision: https://phabricator.services.mozilla.com/D23497
netwerk/protocol/http/nsHttpHandler.cpp
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -2483,18 +2483,19 @@ nsresult nsHttpHandler::SpeculativeConne
 
   int32_t port = -1;
   rv = aURI->GetPort(&port);
   if (NS_FAILED(rv)) return rv;
 
   nsAutoCString username;
   aURI->GetUsername(username);
 
-  auto *ci = new nsHttpConnectionInfo(host, port, EmptyCString(), username,
-                                      nullptr, originAttributes, usingSSL);
+  RefPtr<nsHttpConnectionInfo> ci =
+      new nsHttpConnectionInfo(host, port, EmptyCString(), username, nullptr,
+                               originAttributes, usingSSL);
   ci->SetAnonymous(anonymous);
 
   return SpeculativeConnect(ci, aCallbacks);
 }
 
 NS_IMETHODIMP
 nsHttpHandler::SpeculativeConnect(nsIURI *aURI, nsIPrincipal *aPrincipal,
                                   nsIInterfaceRequestor *aCallbacks) {