Bug 1420673: Use UniquePtr to store nsHostResolver.addr r=valentin
authorJeff Hemphill <jthemphill@gmail.com>
Sat, 25 Nov 2017 23:37:24 -0800
changeset 394146 f5d4fa288571
parent 394047 b680b6a0197e
child 394147 b3d1e9847a7a
push id32994
push userbtara@mozilla.com
push dateWed, 29 Nov 2017 22:37:27 +0000
treeherdermozilla-central@60db335c1726 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1420673
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 1420673: Use UniquePtr to store nsHostResolver.addr r=valentin MozReview-Commit-ID: Arrm0stdtNL
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsHostResolver.cpp
netwerk/dns/nsHostResolver.h
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -152,17 +152,17 @@ nsDNSRecord::GetNextAddr(uint16_t port, 
         mHostRecord->addr_info_lock.Unlock();
 
         if (!mHostRecord->addr) {
             // Both mHostRecord->addr_info and mHostRecord->addr are null.
             // This can happen if mHostRecord->addr_info expired and the
             // attempt to reresolve it failed.
             return NS_ERROR_NOT_AVAILABLE;
         }
-        memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
+        memcpy(addr, mHostRecord->addr.get(), sizeof(NetAddr));
         mDone = true;
     }
 
     // set given port
     port = htons(port);
     if (addr->raw.family == AF_INET) {
         addr->inet.port = port;
     } else if (addr->raw.family == AF_INET6) {
@@ -197,17 +197,17 @@ nsDNSRecord::GetAddresses(nsTArray<NetAd
         mHostRecord->addr_info_lock.Unlock();
     } else {
         mHostRecord->addr_info_lock.Unlock();
 
         if (!mHostRecord->addr) {
             return NS_ERROR_NOT_AVAILABLE;
         }
         NetAddr *addr = aAddressArray.AppendElement(NetAddr());
-        memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
+        memcpy(addr, mHostRecord->addr.get(), sizeof(NetAddr));
         if (addr->raw.family == AF_INET) {
             addr->inet.port = 0;
         } else if (addr->raw.family == AF_INET6) {
             addr->inet6.port = 0;
         }
     }
     return NS_OK;
 }
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -227,17 +227,16 @@ nsHostRecord::CopyExpirationTimesAndFlag
     mGraceStart = aFromHostRecord->mGraceStart;
     mDoomed = aFromHostRecord->mDoomed;
 }
 
 nsHostRecord::~nsHostRecord()
 {
     Telemetry::Accumulate(Telemetry::DNS_BLACKLIST_COUNT, mBlacklistedCount);
     delete addr_info;
-    delete addr;
 }
 
 bool
 nsHostRecord::Blacklisted(NetAddr *aQuery)
 {
     // must call locked
     LOG(("Checking blacklist for host [%s%s%s], host record [%p].\n",
           LOG_HOST(host, netInterface), this));
@@ -348,17 +347,17 @@ nsHostRecord::SizeOfIncludingThis(Malloc
 
     // The |host| field (inherited from nsHostKey) actually points to extra
     // memory that is allocated beyond the end of the nsHostRecord (see
     // nsHostRecord::Create()).  So it will be included in the
     // |mallocSizeOf(this)| call above.
 
     n += SizeOfResolveHostCallbackListExcludingHead(&callbacks, mallocSizeOf);
     n += addr_info ? addr_info->SizeOfIncludingThis(mallocSizeOf) : 0;
-    n += mallocSizeOf(addr);
+    n += mallocSizeOf(addr.get());
 
     n += mBlacklistedItems.ShallowSizeOfExcludingThis(mallocSizeOf);
     for (size_t i = 0; i < mBlacklistedItems.Length(); i++) {
         n += mBlacklistedItems[i].SizeOfExcludingThisIfUnshared(mallocSizeOf);
     }
     return n;
 }
 
@@ -813,18 +812,18 @@ nsHostResolver::ResolveHost(const char  
             }
             // try parsing the host name as an IP address literal to short
             // circuit full host resolution.  (this is necessary on some
             // platforms like Win9x.  see bug 219376 for more details.)
             else if (PR_StringToNetAddr(host, &tempAddr) == PR_SUCCESS) {
                 LOG(("  Host is IP Literal [%s].\n", host));
                 // ok, just copy the result into the host record, and be done
                 // with it! ;-)
-                he->rec->addr = new NetAddr();
-                PRNetAddrToNetAddr(&tempAddr, he->rec->addr);
+                he->rec->addr = MakeUnique<NetAddr>();
+                PRNetAddrToNetAddr(&tempAddr, he->rec->addr.get());
                 // put reference to host record on stack...
                 Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
                                       METHOD_LITERAL);
                 result = he->rec;
             }
             else if (mPendingCount >= MAX_NON_PRIORITY_REQUESTS &&
                      !IsHighPriority(flags) &&
                      !he->rec->resolving) {
--- a/netwerk/dns/nsHostResolver.h
+++ b/netwerk/dns/nsHostResolver.h
@@ -16,16 +16,17 @@
 #include "nsIDNSListener.h"
 #include "nsIDNSService.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "GetAddrInfo.h"
 #include "mozilla/net/DNS.h"
 #include "mozilla/net/DashboardTypes.h"
 #include "mozilla/TimeStamp.h"
+#include "mozilla/UniquePtr.h"
 
 class nsHostResolver;
 class nsHostRecord;
 class nsResolveHostCallback;
 
 #define MAX_RESOLVER_THREADS_FOR_ANY_PRIORITY  3
 #define MAX_RESOLVER_THREADS_FOR_HIGH_PRIORITY 5
 #define MAX_NON_PRIORITY_REQUESTS 150
@@ -70,17 +71,17 @@ public:
      * assigned a value.  only the resolver worker thread modifies
      * nsHostRecord (and only in nsHostResolver::OnLookupComplete);
      * the other threads just read it.  therefore the resolver worker
      * thread doesn't need to lock when reading |addr_info|.
      */
     Mutex        addr_info_lock;
     int          addr_info_gencnt; /* generation count of |addr_info| */
     mozilla::net::AddrInfo *addr_info;
-    mozilla::net::NetAddr  *addr;
+    mozilla::UniquePtr<mozilla::net::NetAddr> addr;
     bool         negative;   /* True if this record is a cache of a failed lookup.
                                 Negative cache entries are valid just like any other
                                 (though never for more than 60 seconds), but a use
                                 of that negative entry forces an asynchronous refresh. */
 
     enum ExpirationStatus {
         EXP_VALID,
         EXP_GRACE,