From 95aaaa57737bfb808648f58749eab6587878cd3f Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Mon, 4 Dec 2017 16:02:59 +0100 Subject: [PATCH] Bug 1422173 - Backed out changeset 27719294cb73 (Bug 1420677) r=me MozReview-Commit-ID: 7iSG4279EfL --- netwerk/dns/GetAddrInfo.cpp | 22 +++++++++++----------- netwerk/dns/GetAddrInfo.h | 3 +-- netwerk/dns/nsHostResolver.cpp | 27 +++++++++++++++------------ netwerk/dns/nsHostResolver.h | 5 ++--- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/netwerk/dns/GetAddrInfo.cpp b/netwerk/dns/GetAddrInfo.cpp index 45bc1708406f..c25822e74736 100644 --- a/netwerk/dns/GetAddrInfo.cpp +++ b/netwerk/dns/GetAddrInfo.cpp @@ -251,9 +251,10 @@ _GetTTLData_Windows(const char* aHost, uint32_t* aResult, uint16_t aAddressFamil static MOZ_ALWAYS_INLINE nsresult _GetAddrInfo_Portable(const char* aCanonHost, uint16_t aAddressFamily, uint16_t aFlags, const char* aNetworkInterface, - UniquePtr& aAddrInfo) + AddrInfo** aAddrInfo) { MOZ_ASSERT(aCanonHost); + MOZ_ASSERT(aAddrInfo); // We accept the same aFlags that nsHostResolver::ResolveHost accepts, but we // need to translate the aFlags into a form that PR_GetAddrInfoByName @@ -282,14 +283,14 @@ _GetAddrInfo_Portable(const char* aCanonHost, uint16_t aAddressFamily, } bool filterNameCollision = !(aFlags & nsHostResolver::RES_ALLOW_NAME_COLLISION); - auto ai = MakeUnique(aCanonHost, prai, disableIPv4, - filterNameCollision, canonName); + nsAutoPtr ai(new AddrInfo(aCanonHost, prai, disableIPv4, + filterNameCollision, canonName)); PR_FreeAddrInfo(prai); if (ai->mAddresses.isEmpty()) { return NS_ERROR_UNKNOWN_HOST; } - aAddrInfo = Move(ai); + *aAddrInfo = ai.forget(); return NS_OK; } @@ -321,10 +322,9 @@ GetAddrInfoShutdown() { nsresult GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags, - const char* aNetworkInterface, - UniquePtr& aAddrInfo, bool aGetTtl) + const char* aNetworkInterface, AddrInfo** aAddrInfo, bool aGetTtl) { - if (NS_WARN_IF(!aHost)) { + if (NS_WARN_IF(!aHost) || NS_WARN_IF(!aAddrInfo)) { return NS_ERROR_NULL_POINTER; } @@ -335,7 +335,7 @@ GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags, } #endif - aAddrInfo = nullptr; + *aAddrInfo = nullptr; nsresult rv = _GetAddrInfo_Portable(aHost, aAddressFamily, aFlags, aNetworkInterface, aAddrInfo); @@ -344,8 +344,8 @@ GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags, // Figure out the canonical name, or if that fails, just use the host name // we have. const char *name = nullptr; - if (aAddrInfo && aAddrInfo->mCanonicalName) { - name = aAddrInfo->mCanonicalName; + if (*aAddrInfo != nullptr && (*aAddrInfo)->mCanonicalName) { + name = (*aAddrInfo)->mCanonicalName; } else { name = aHost; } @@ -354,7 +354,7 @@ GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags, uint32_t ttl = 0; nsresult ttlRv = _GetTTLData_Windows(name, &ttl, aAddressFamily); if (NS_SUCCEEDED(ttlRv)) { - aAddrInfo->ttl = ttl; + (*aAddrInfo)->ttl = ttl; LOG("Got TTL %u for %s (name = %s).", ttl, aHost, name); } else { LOG_WARNING("Could not get TTL for %s (cname = %s).", aHost, name); diff --git a/netwerk/dns/GetAddrInfo.h b/netwerk/dns/GetAddrInfo.h index a591fbe00c8f..57c008dd506c 100644 --- a/netwerk/dns/GetAddrInfo.h +++ b/netwerk/dns/GetAddrInfo.h @@ -40,8 +40,7 @@ class AddrInfo; */ nsresult GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags, - const char* aNetworkInterface, - UniquePtr& aAddrInfo, bool aGetTtl); + const char* aNetworkInterface, AddrInfo** aAddrInfo, bool aGetTtl); /** * Initialize the GetAddrInfo module. diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index df70ef610f9a..4929764bd10f 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -231,6 +231,7 @@ nsHostRecord::CopyExpirationTimesAndFlagsFrom(const nsHostRecord *aFromHostRecor nsHostRecord::~nsHostRecord() { Telemetry::Accumulate(Telemetry::DNS_BLACKLIST_COUNT, mBlacklistedCount); + delete addr_info; } bool @@ -598,8 +599,7 @@ nsHostResolver::ClearPendingQueue(PRCList *aPendingQ) while (node != aPendingQ) { nsHostRecord *rec = static_cast(node); node = node->next; - OnLookupComplete(rec, NS_ERROR_ABORT, - mozilla::UniquePtr(nullptr)); + OnLookupComplete(rec, NS_ERROR_ABORT, nullptr); } } } @@ -884,7 +884,7 @@ nsHostResolver::ResolveHost(const char *host, if ((af == addrIter->mAddress.inet.family) && !unspecHe->rec->Blacklisted(&addrIter->mAddress)) { if (!he->rec->addr_info) { - he->rec->addr_info = mozilla::MakeUnique( + he->rec->addr_info = new AddrInfo( unspecHe->rec->addr_info->mHostName, unspecHe->rec->addr_info->mCanonicalName); he->rec->CopyExpirationTimesAndFlagsFrom(unspecHe->rec); @@ -1286,8 +1286,7 @@ different_rrset(AddrInfo *rrset1, AddrInfo *rrset2) // returns LOOKUP_RESOLVEAGAIN, but only if 'status' is not NS_ERROR_ABORT. // takes ownership of AddrInfo parameter nsHostResolver::LookupStatus -nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, - mozilla::UniquePtr&& newRRSet) +nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, AddrInfo* newRRSet) { // get the list of pending callbacks for this lookup, and notify // them that the lookup is complete. @@ -1299,6 +1298,7 @@ nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, if (rec->mResolveAgain && (status != NS_ERROR_ABORT)) { LOG(("nsHostResolver record %p resolve again due to flushcache\n", rec)); rec->mResolveAgain = false; + delete newRRSet; return LOOKUP_RESOLVEAGAIN; } @@ -1307,18 +1307,22 @@ nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, // update record fields. We might have a rec->addr_info already if a // previous lookup result expired and we're reresolving it.. + AddrInfo *old_addr_info; { MutexAutoLock lock(rec->addr_info_lock); - if (different_rrset(rec->addr_info.get(), newRRSet.get())) { + if (different_rrset(rec->addr_info, newRRSet)) { LOG(("nsHostResolver record %p new gencnt\n", rec)); - rec->addr_info = Move(newRRSet); + old_addr_info = rec->addr_info; + rec->addr_info = newRRSet; rec->addr_info_gencnt++; } else { if (rec->addr_info && newRRSet) { rec->addr_info->ttl = newRRSet->ttl; } + old_addr_info = newRRSet; } } + delete old_addr_info; rec->negative = !rec->addr_info; PrepareRecordExpiration(rec); @@ -1468,7 +1472,7 @@ nsHostResolver::ThreadFunc(void *arg) #endif nsHostResolver *resolver = (nsHostResolver *)arg; nsHostRecord *rec = nullptr; - mozilla::UniquePtr ai = nullptr; + AddrInfo *ai = nullptr; while (rec || resolver->GetHostToLookup(&rec)) { LOG(("DNS lookup thread - Calling getaddrinfo for host [%s%s%s].\n", @@ -1482,10 +1486,10 @@ nsHostResolver::ThreadFunc(void *arg) #endif nsresult status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface, - ai, getTtl); + &ai, getTtl); #if defined(RES_RETRY_ON_FAILURE) if (NS_FAILED(status) && rs.Reset()) { - status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface, ai, + status = GetAddrInfo(rec->host, rec->af, rec->flags, rec->netInterface, &ai, getTtl); } #endif @@ -1521,8 +1525,7 @@ nsHostResolver::ThreadFunc(void *arg) LOG_HOST(rec->host, rec->netInterface), ai ? "success" : "failure: unknown host")); - if (LOOKUP_RESOLVEAGAIN == resolver->OnLookupComplete(rec, status, - mozilla::Move(ai))) { + if (LOOKUP_RESOLVEAGAIN == resolver->OnLookupComplete(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, rec->netInterface))); diff --git a/netwerk/dns/nsHostResolver.h b/netwerk/dns/nsHostResolver.h index 8226cdf6b262..a4d26982fff1 100644 --- a/netwerk/dns/nsHostResolver.h +++ b/netwerk/dns/nsHostResolver.h @@ -75,7 +75,7 @@ public: */ Mutex addr_info_lock; int addr_info_gencnt; /* generation count of |addr_info| */ - mozilla::UniquePtr addr_info; + mozilla::net::AddrInfo *addr_info; mozilla::UniquePtr addr; bool negative; /* True if this record is a cache of a failed lookup. Negative cache entries are valid just like any other @@ -318,8 +318,7 @@ private: LOOKUP_RESOLVEAGAIN, }; - LookupStatus OnLookupComplete(nsHostRecord *, nsresult, - mozilla::UniquePtr&&); + LookupStatus OnLookupComplete(nsHostRecord *, nsresult, mozilla::net::AddrInfo *); void DeQueue(PRCList &aQ, nsHostRecord **aResult); void ClearPendingQueue(PRCList *aPendingQueue); nsresult ConditionallyCreateThread(nsHostRecord *rec);