Bug 1472788 - Use smart pointers in nsHostResolver::Create r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 02 Jul 2018 21:46:16 +0000
changeset 424754 0032f8f594fa6153d98b039515375b71e5bb550a
parent 424753 4f695620856d81f7457cc7f2f194b664009d633c
child 424755 2a62423eaaa98c3829226ad181caad94d5e72d24
push id65848
push uservalentin.gosu@gmail.com
push dateTue, 03 Jul 2018 07:59:13 +0000
treeherderautoland@0032f8f594fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1472788
milestone63.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 1472788 - Use smart pointers in nsHostResolver::Create r=bagder Small patch to test out phabricator Differential Revision: https://phabricator.services.mozilla.com/D1916
netwerk/dns/nsHostResolver.cpp
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -1886,26 +1886,27 @@ nsHostResolver::SetCacheLimits(uint32_t 
 }
 
 nsresult
 nsHostResolver::Create(uint32_t maxCacheEntries,
                        uint32_t defaultCacheEntryLifetime,
                        uint32_t defaultGracePeriod,
                        nsHostResolver **result)
 {
-    auto *res = new nsHostResolver(maxCacheEntries, defaultCacheEntryLifetime,
-                                   defaultGracePeriod);
-    NS_ADDREF(res);
+    RefPtr<nsHostResolver> res =
+        new nsHostResolver(maxCacheEntries, defaultCacheEntryLifetime,
+                           defaultGracePeriod);
 
     nsresult rv = res->Init();
-    if (NS_FAILED(rv))
-        NS_RELEASE(res);
+    if (NS_FAILED(rv)) {
+        return rv;
+    }
 
-    *result = res;
-    return rv;
+    res.forget(result);
+    return NS_OK;
 }
 
 void
 nsHostResolver::GetDNSCacheEntries(nsTArray<DNSCacheEntries> *args)
 {
     MutexAutoLock lock(mLock);
     for (auto iter = mRecordDB.Iter(); !iter.Done(); iter.Next()) {
         // We don't pay attention to address literals, only resolved domains.