Bug 1422173 - Backed out changeset 34cfc821e335 (Bug 1417827) r=me
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 04 Dec 2017 16:02:58 +0100
changeset 394886 90b7c07853ac
parent 394885 b0f2a1cfbd45
child 394887 c954378b4af3
push id33020
push userbtara@mozilla.com
push dateMon, 04 Dec 2017 20:21:20 +0000
treeherdermozilla-central@7d191882de19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1422173, 1417827
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 1422173 - Backed out changeset 34cfc821e335 (Bug 1417827) r=me MozReview-Commit-ID: 5C5YN8zgAgt
netwerk/dns/DNS.cpp
netwerk/dns/DNS.h
netwerk/dns/GetAddrInfo.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsHostResolver.cpp
--- a/netwerk/dns/DNS.cpp
+++ b/netwerk/dns/DNS.cpp
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/net/DNS.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/mozalloc.h"
 #include "mozilla/ArrayUtils.h"
-#include "nsString.h"
 #include <string.h>
 
 #ifdef XP_WIN
 #include "ws2tcpip.h"
 #endif
 
 namespace mozilla {
 namespace net {
@@ -287,67 +286,89 @@ NetAddrElement::NetAddrElement(const PRN
 
 NetAddrElement::NetAddrElement(const NetAddrElement& netAddr)
 {
   mAddress = netAddr.mAddress;
 }
 
 NetAddrElement::~NetAddrElement() = default;
 
-AddrInfo::AddrInfo(const nsACString& host, const PRAddrInfo *prAddrInfo,
-                   bool disableIPv4, bool filterNameCollision,
-                   const nsACString& cname)
-  : mHostName(host)
-  , mCanonicalName(cname)
+AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo,
+                   bool disableIPv4, bool filterNameCollision, const char *cname)
+  : mHostName(nullptr)
+  , mCanonicalName(nullptr)
   , ttl(NO_TTL_DATA)
 {
   MOZ_ASSERT(prAddrInfo, "Cannot construct AddrInfo with a null prAddrInfo pointer!");
   const uint32_t nameCollisionAddr = htonl(0x7f003535); // 127.0.53.53
 
+  Init(host, cname);
   PRNetAddr tmpAddr;
   void *iter = nullptr;
   do {
     iter = PR_EnumerateAddrInfo(iter, prAddrInfo, 0, &tmpAddr);
     bool addIt = iter &&
         (!disableIPv4 || tmpAddr.raw.family != PR_AF_INET) &&
         (!filterNameCollision || tmpAddr.raw.family != PR_AF_INET || (tmpAddr.inet.ip != nameCollisionAddr));
     if (addIt) {
         auto *addrElement = new NetAddrElement(&tmpAddr);
         mAddresses.insertBack(addrElement);
     }
   } while (iter);
 }
 
-AddrInfo::AddrInfo(const nsACString& host, const nsACString& cname)
-  : mHostName(host)
-  , mCanonicalName(cname)
+AddrInfo::AddrInfo(const char *host, const char *cname)
+  : mHostName(nullptr)
+  , mCanonicalName(nullptr)
   , ttl(NO_TTL_DATA)
 {
+  Init(host, cname);
 }
 
 AddrInfo::~AddrInfo()
 {
   NetAddrElement *addrElement;
   while ((addrElement = mAddresses.popLast())) {
     delete addrElement;
   }
+  free(mHostName);
+  free(mCanonicalName);
+}
+
+void
+AddrInfo::Init(const char *host, const char *cname)
+{
+  MOZ_ASSERT(host, "Cannot initialize AddrInfo with a null host pointer!");
+
+  ttl = NO_TTL_DATA;
+  size_t hostlen = strlen(host);
+  mHostName = static_cast<char*>(moz_xmalloc(hostlen + 1));
+  memcpy(mHostName, host, hostlen + 1);
+  if (cname) {
+    size_t cnameLen = strlen(cname);
+    mCanonicalName = static_cast<char*>(moz_xmalloc(cnameLen + 1));
+    memcpy(mCanonicalName, cname, cnameLen + 1);
+  }
+  else {
+    mCanonicalName = nullptr;
+  }
 }
 
 void
 AddrInfo::AddAddress(NetAddrElement *address)
 {
   MOZ_ASSERT(address, "Cannot add the address to an uninitialized list");
 
   mAddresses.insertBack(address);
 }
 
 size_t
 AddrInfo::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
 {
   size_t n = mallocSizeOf(this);
-  n += mHostName.SizeOfExcludingThisIfUnshared(mallocSizeOf);
-  n += mCanonicalName.SizeOfExcludingThisIfUnshared(mallocSizeOf);
+  n += mallocSizeOf(mHostName);
+  n += mallocSizeOf(mCanonicalName);
   n += mAddresses.sizeOfExcludingThis(mallocSizeOf);
   return n;
 }
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/dns/DNS.h
+++ b/netwerk/dns/DNS.h
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef DNS_h_
 #define DNS_h_
 
 #include "nscore.h"
-#include "nsString.h"
 #include "prio.h"
 #include "prnetdb.h"
 #include "plstr.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
 
 #if !defined(XP_WIN)
 #include <arpa/inet.h>
@@ -129,37 +128,38 @@ public:
   NetAddrElement(const NetAddrElement& netAddr);
   ~NetAddrElement();
 
   NetAddr mAddress;
 };
 
 class AddrInfo {
 public:
-  // Creates an AddrInfo object.
-  AddrInfo(const nsACString& host, const PRAddrInfo *prAddrInfo,
-           bool disableIPv4, bool filterNameCollision,
-           const nsACString& cname);
+  // Creates an AddrInfo object. It calls the AddrInfo(const char*, const char*)
+  // to initialize the host and the cname.
+  AddrInfo(const char *host, const PRAddrInfo *prAddrInfo, bool disableIPv4,
+           bool filterNameCollision, const char *cname);
 
-  // Creates a basic AddrInfo object (initialize only the host and the
-  // cname).
-  AddrInfo(const nsACString& host, const nsACString& cname);
-
+  // Creates a basic AddrInfo object (initialize only the host and the cname).
+  AddrInfo(const char *host, const char *cname);
   ~AddrInfo();
 
   void AddAddress(NetAddrElement *address);
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
 
-  nsCString mHostName;
-  nsCString mCanonicalName;
+  char *mHostName;
+  char *mCanonicalName;
   uint32_t ttl;
   static const uint32_t NO_TTL_DATA = (uint32_t) -1;
 
   LinkedList<NetAddrElement> mAddresses;
+
+private:
+  void Init(const char *host, const char *cname);
 };
 
 // Copies the contents of a PRNetAddr to a NetAddr.
 // Does not do a ptr safety check!
 void PRNetAddrToNetAddr(const PRNetAddr *prAddr, NetAddr *addr);
 
 // Copies the contents of a NetAddr to a PRNetAddr.
 // Does not do a ptr safety check!
--- a/netwerk/dns/GetAddrInfo.cpp
+++ b/netwerk/dns/GetAddrInfo.cpp
@@ -277,18 +277,18 @@ static MOZ_ALWAYS_INLINE nsresult
   }
 
   const char* canonName = nullptr;
   if (aFlags & nsHostResolver::RES_CANON_NAME) {
     canonName = PR_GetCanonNameFromAddrInfo(prai);
   }
 
   bool filterNameCollision = !(aFlags & nsHostResolver::RES_ALLOW_NAME_COLLISION);
-  auto ai = MakeUnique<AddrInfo>(nsCString(aCanonHost), prai, disableIPv4,
-                                 filterNameCollision, nsCString(canonName));
+  auto ai = MakeUnique<AddrInfo>(aCanonHost, prai, disableIPv4,
+                                 filterNameCollision, canonName);
   PR_FreeAddrInfo(prai);
   if (ai->mAddresses.isEmpty()) {
     return NS_ERROR_UNKNOWN_HOST;
   }
 
   aAddrInfo = Move(ai);
 
   return NS_OK;
@@ -339,18 +339,18 @@ GetAddrInfo(const char* aHost, uint16_t 
   nsresult rv = _GetAddrInfo_Portable(aHost, aAddressFamily, aFlags,
                                       aNetworkInterface, aAddrInfo);
 
 #if DNSQUERY_AVAILABLE
   if (aGetTtl && NS_SUCCEEDED(rv)) {
     // Figure out the canonical name, or if that fails, just use the host name
     // we have.
     const char *name = nullptr;
-    if (aAddrInfo && !aAddrInfo->mCanonicalName.IsEmpty()) {
-      name = aAddrInfo->mCanonicalName.get();
+    if (aAddrInfo && aAddrInfo->mCanonicalName) {
+      name = aAddrInfo->mCanonicalName;
     } else {
       name = aHost;
     }
 
     LOG("Getting TTL for %s (cname = %s).", aHost, name);
     uint32_t ttl = 0;
     nsresult ttlRv = _GetTTLData_Windows(name, &ttl, aAddressFamily);
     if (NS_SUCCEEDED(ttlRv)) {
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -83,31 +83,28 @@ NS_IMPL_ISUPPORTS(nsDNSRecord, nsIDNSRec
 
 NS_IMETHODIMP
 nsDNSRecord::GetCanonicalName(nsACString &result)
 {
     // this method should only be called if we have a CNAME
     NS_ENSURE_TRUE(mHostRecord->flags & nsHostResolver::RES_CANON_NAME,
                    NS_ERROR_NOT_AVAILABLE);
 
+    // if the record is for an IP address literal, then the canonical
+    // host name is the IP address literal.
+    const char *cname;
     {
         MutexAutoLock lock(mHostRecord->addr_info_lock);
-
-        // if the record is for an IP address literal, then the canonical
-        // host name is the IP address literal.
-        if (!mHostRecord->addr_info) {
-            result = mHostRecord->host;
-            return NS_OK;
-        }
-
-        if (mHostRecord->addr_info->mCanonicalName.IsEmpty()) {
-            result = mHostRecord->addr_info->mHostName;
-        } else {
-            result = mHostRecord->addr_info->mCanonicalName;
-        }
+        if (mHostRecord->addr_info)
+            cname = mHostRecord->addr_info->mCanonicalName ?
+                mHostRecord->addr_info->mCanonicalName :
+                mHostRecord->addr_info->mHostName;
+        else
+            cname = mHostRecord->host;
+        result.Assign(cname);
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDNSRecord::GetNextAddr(uint16_t port, NetAddr *addr)
 {
     if (mDone) {
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -1235,17 +1235,17 @@ nsHostResolver::PrepareRecordExpiration(
 
 static bool
 different_rrset(AddrInfo *rrset1, AddrInfo *rrset2)
 {
     if (!rrset1 || !rrset2) {
         return true;
     }
 
-    LOG(("different_rrset %s\n", rrset1->mHostName.get()));
+    LOG(("different_rrset %s\n", rrset1->mHostName));
     nsTArray<NetAddr> orderedSet1;
     nsTArray<NetAddr> orderedSet2;
 
     for (NetAddrElement *element = rrset1->mAddresses.getFirst();
          element; element = element->getNext()) {
         if (LOG_ENABLED()) {
             char buf[128];
             NetAddrToString(&element->mAddress, buf, 128);