Bug 1427373 - Use a refPtr for rec so that CompleteLookup doesn't need to release it r=mayhemer
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 07 Jan 2018 23:00:07 +0100
changeset 452901 aaa8ca204b8bbd679675c8ded026e2a511f8c80c
parent 452900 3d586753feb287817d5aaca606564bca2335ea90
child 452902 d739ece3bea212375d0b02f998ebd4a3b861ced9
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1427373
milestone59.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 1427373 - Use a refPtr for rec so that CompleteLookup doesn't need to release it r=mayhemer MozReview-Commit-ID: 4LUxxJ13Bg3
netwerk/dns/nsHostResolver.cpp
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -591,17 +591,17 @@ nsHostResolver::Init()
 
 void
 nsHostResolver::ClearPendingQueue(PRCList *aPendingQ)
 {
     // loop through pending queue, erroring out pending lookups.
     if (!PR_CLIST_IS_EMPTY(aPendingQ)) {
         PRCList *node = aPendingQ->next;
         while (node != aPendingQ) {
-            nsHostRecord *rec = static_cast<nsHostRecord *>(node);
+            RefPtr<nsHostRecord> rec = dont_AddRef(static_cast<nsHostRecord *>(node));
             node = node->next;
             CompleteLookup(rec, NS_ERROR_ABORT, nullptr);
         }
     }
 }
 
 //
 // FlushCache() is what we call when the network has changed. We must not
@@ -1381,18 +1381,16 @@ nsHostResolver::CompleteLookup(nsHostRec
 #endif
         }
     }
 
     for (nsResolveHostCallback* c = cbs.getFirst(); c; c = c->removeAndGetNext()) {
         c->OnResolveHostComplete(this, rec, status);
     }
 
-    NS_RELEASE(rec);
-
     return LOOKUP_OK;
 }
 
 void
 nsHostResolver::CancelAsyncRequest(const char             *host,
                                    const OriginAttributes &aOriginAttributes,
                                    uint16_t                flags,
                                    uint16_t                af,
@@ -1465,20 +1463,20 @@ nsHostResolver::ThreadFunc(void *arg)
 
     AUTO_PROFILER_REGISTER_THREAD(name.BeginReading());
     NS_SetCurrentThreadName(name.BeginReading());
 
 #if defined(RES_RETRY_ON_FAILURE)
     nsResState rs;
 #endif
     RefPtr<nsHostResolver> resolver = dont_AddRef((nsHostResolver *)arg);
-    nsHostRecord *rec  = nullptr;
+    RefPtr<nsHostRecord> rec;
     AddrInfo *ai = nullptr;
 
-    while (rec || resolver->GetHostToLookup(&rec)) {
+    while (rec || resolver->GetHostToLookup(getter_AddRefs(rec))) {
         LOG(("DNS lookup thread - Calling getaddrinfo for host [%s%s%s].\n",
              LOG_HOST(rec->host.get(), rec->netInterface.get())));
 
         TimeStamp startTime = TimeStamp::Now();
 #if TTL_AVAILABLE
         bool getTtl = rec->mGetTtl;
 #else
         bool getTtl = false;
@@ -1517,17 +1515,16 @@ nsHostResolver::ThreadFunc(void *arg)
                     }
                     Telemetry::Accumulate(histogramID, millis);
                 } else {
                     Telemetry::Accumulate(Telemetry::DNS_FAILED_LOOKUP_TIME, millis);
                 }
             }
         }
 
-        // CompleteLookup may release "rec", long before we lose it.
         LOG(("DNS lookup thread - lookup completed for host [%s%s%s]: %s.\n",
              LOG_HOST(rec->host.get(), rec->netInterface.get()),
              ai ? "success" : "failure: unknown host"));
 
         if (LOOKUP_RESOLVEAGAIN == resolver->CompleteLookup(rec, status, ai)) {
             // leave 'rec' assigned and loop to make a renewed host resolve
             LOG(("DNS lookup thread - Re-resolving host [%s%s%s].\n",
                  LOG_HOST(rec->host.get(), rec->netInterface.get())));