Bug 1512472 - Hold nsHttpConnectionInfo in a RefPtr to avoid leak when returning early r=dragana
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 19 Mar 2019 12:03:23 +0000
changeset 465009 e94a55919deaae4fa117d64dd9404f4e85dad7fd
parent 465008 137d3d35a3645f6b1ca4bbbb3eb2dbbeeeea0d73
child 465010 7da042469ac075f8504be068c505ff0a868a8b77
push id112486
push useropoprus@mozilla.com
push dateTue, 19 Mar 2019 16:41:04 +0000
treeherdermozilla-inbound@ee866fb50236 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1512472
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1512472 - Hold nsHttpConnectionInfo in a RefPtr to avoid leak when returning early r=dragana 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
@@ -2486,18 +2486,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) {