Bug 997686 - SocketTransportService infaliible malloc cleanup r=sworkman
authorPatrick McManus <mcmanus@ducksong.com>
Tue, 15 Apr 2014 22:41:06 -0400
changeset 179160 2ec02b778be10e4d51cc31cd1ee96c7ca90420cc
parent 179159 caf503c905c024715145b014bf02245d117b357f
child 179161 779b111e77f623c40b32f9bcdc56afa1cc2a14df
push id26607
push userryanvm@gmail.com
push dateFri, 18 Apr 2014 02:31:26 +0000
treeherdermozilla-central@7fe3ee0cf8be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs997686
milestone31.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 997686 - SocketTransportService infaliible malloc cleanup r=sworkman
netwerk/base/src/nsSocketTransportService2.cpp
--- a/netwerk/base/src/nsSocketTransportService2.cpp
+++ b/netwerk/base/src/nsSocketTransportService2.cpp
@@ -614,28 +614,23 @@ nsSocketTransportService::CreateTranspor
                                           const nsACString &host,
                                           int32_t port,
                                           nsIProxyInfo *proxyInfo,
                                           nsISocketTransport **result)
 {
     NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
     NS_ENSURE_TRUE(port >= 0 && port <= 0xFFFF, NS_ERROR_ILLEGAL_VALUE);
 
-    nsSocketTransport *trans = new nsSocketTransport();
-    if (!trans)
-        return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(trans);
-
+    nsRefPtr<nsSocketTransport> trans = new nsSocketTransport();
     nsresult rv = trans->Init(types, typeCount, host, port, proxyInfo);
     if (NS_FAILED(rv)) {
-        NS_RELEASE(trans);
         return rv;
     }
 
-    *result = trans;
+    trans.forget(result);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath,
                                                     nsISocketTransport **result)
 {
     nsresult rv;
@@ -643,18 +638,16 @@ nsSocketTransportService::CreateUnixDoma
     NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
 
     nsAutoCString path;
     rv = aPath->GetNativePath(path);
     if (NS_FAILED(rv))
         return rv;
 
     nsRefPtr<nsSocketTransport> trans = new nsSocketTransport();
-    if (!trans)
-        return NS_ERROR_OUT_OF_MEMORY;
 
     rv = trans->InitWithFilename(path.get());
     if (NS_FAILED(rv))
         return rv;
 
     trans.forget(result);
     return NS_OK;
 }