Bug 1301069 - Backed out bug 1185120 (changeset 38cad72a77a6) a=backout a=merge

--HG--
extra : source : 9330dc01ec0245f05311c56025a50705138351bc
This commit is contained in:
Valentin Gosu 2016-09-08 00:04:07 +02:00
Родитель 5cbc382303
Коммит fe9b24270d
7 изменённых файлов: 50 добавлений и 33 удалений

Просмотреть файл

@ -76,6 +76,10 @@ leak:processInternalEntity
# Bug 1187421 - With e10s, NSS does not always free the error stack. m1.
leak:nss_ClearErrorStack
# Bug 1189430 - DNS leaks in mochitest-chrome.
leak:nsDNSService::AsyncResolveExtended
leak:_GetAddrInfo_Portable
# Bug 1189568 - Indirect leaks of IMContextWrapper and nsIntRect.
leak:nsWindow::Create
leak:nsBaseWidget::StoreWindowClipRegion

Просмотреть файл

@ -284,7 +284,9 @@ NetAddrElement::~NetAddrElement()
AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo,
bool disableIPv4, bool filterNameCollision, const char *cname)
: ttl(NO_TTL_DATA)
: 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
@ -305,7 +307,9 @@ AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo,
}
AddrInfo::AddrInfo(const char *host, const char *cname)
: ttl(NO_TTL_DATA)
: mHostName(nullptr)
, mCanonicalName(nullptr)
, ttl(NO_TTL_DATA)
{
Init(host, cname);
}
@ -316,6 +320,8 @@ AddrInfo::~AddrInfo()
while ((addrElement = mAddresses.popLast())) {
delete addrElement;
}
free(mHostName);
free(mCanonicalName);
}
void
@ -325,13 +331,15 @@ AddrInfo::Init(const char *host, const char *cname)
ttl = NO_TTL_DATA;
size_t hostlen = strlen(host);
mHostName = mozilla::MakeUnique<char[]>(hostlen + 1);
memcpy(mHostName.get(), host, hostlen + 1);
mHostName = static_cast<char*>(moz_xmalloc(hostlen + 1));
memcpy(mHostName, host, hostlen + 1);
if (cname) {
size_t cnameLen = strlen(cname);
mCanonicalName = mozilla::MakeUnique<char[]>(cnameLen + 1);
memcpy(mCanonicalName.get(), cname, cnameLen + 1);
mCanonicalName = static_cast<char*>(moz_xmalloc(cnameLen + 1));
memcpy(mCanonicalName, cname, cnameLen + 1);
}
else {
mCanonicalName = nullptr;
}
}
@ -347,8 +355,8 @@ size_t
AddrInfo::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
{
size_t n = mallocSizeOf(this);
n += mallocSizeOf(mHostName.get());
n += mallocSizeOf(mCanonicalName.get());
n += mallocSizeOf(mHostName);
n += mallocSizeOf(mCanonicalName);
n += mAddresses.sizeOfExcludingThis(mallocSizeOf);
return n;
}

Просмотреть файл

@ -13,7 +13,6 @@
#include "plstr.h"
#include "mozilla/LinkedList.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/UniquePtr.h"
#if !defined(XP_WIN)
#include <arpa/inet.h>
@ -142,8 +141,8 @@ public:
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
UniquePtr<char[]> mHostName;
UniquePtr<char[]> mCanonicalName;
char *mHostName;
char *mCanonicalName;
uint16_t ttl;
static const uint16_t NO_TTL_DATA = (uint16_t) -1;

Просмотреть файл

@ -345,7 +345,7 @@ GetAddrInfo(const char* aHost, uint16_t aAddressFamily, uint16_t aFlags,
// we have.
const char *name = nullptr;
if (*aAddrInfo != nullptr && (*aAddrInfo)->mCanonicalName) {
name = (*aAddrInfo)->mCanonicalName.get();
name = (*aAddrInfo)->mCanonicalName;
} else {
name = aHost;
}

Просмотреть файл

@ -93,9 +93,9 @@ nsDNSRecord::GetCanonicalName(nsACString &result)
{
MutexAutoLock lock(mHostRecord->addr_info_lock);
if (mHostRecord->addr_info)
cname = !mHostRecord->addr_info->mCanonicalName.get() ?
mHostRecord->addr_info->mCanonicalName.get() :
mHostRecord->addr_info->mHostName.get();
cname = mHostRecord->addr_info->mCanonicalName ?
mHostRecord->addr_info->mCanonicalName :
mHostRecord->addr_info->mHostName;
else
cname = mHostRecord->host;
result.Assign(cname);
@ -156,7 +156,7 @@ nsDNSRecord::GetNextAddr(uint16_t port, NetAddr *addr)
// attempt to reresolve it failed.
return NS_ERROR_NOT_AVAILABLE;
}
memcpy(addr, mHostRecord->addr.get(), sizeof(NetAddr));
memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
mDone = true;
}
@ -201,7 +201,7 @@ nsDNSRecord::GetAddresses(nsTArray<NetAddr> & aAddressArray)
return NS_ERROR_NOT_AVAILABLE;
}
NetAddr *addr = aAddressArray.AppendElement(NetAddr());
memcpy(addr, mHostRecord->addr.get(), sizeof(NetAddr));
memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
if (addr->raw.family == AF_INET) {
addr->inet.port = 0;
} else if (addr->raw.family == AF_INET6) {

Просмотреть файл

@ -164,6 +164,8 @@ IsLowPriority(uint16_t flags)
nsHostRecord::nsHostRecord(const nsHostKey *key)
: addr_info_lock("nsHostRecord.addr_info_lock")
, addr_info_gencnt(0)
, addr_info(nullptr)
, addr(nullptr)
, negative(false)
, resolving(false)
, onQueue(false)
@ -224,6 +226,8 @@ nsHostRecord::CopyExpirationTimesAndFlagsFrom(const nsHostRecord *aFromHostRecor
nsHostRecord::~nsHostRecord()
{
Telemetry::Accumulate(Telemetry::DNS_BLACKLIST_COUNT, mBlacklistedCount);
delete addr_info;
delete addr;
}
bool
@ -313,7 +317,7 @@ nsHostRecord::HasUsableResult(const mozilla::TimeStamp& now, uint16_t queryFlags
return false;
}
return addr_info.get() || addr.get() || negative;
return addr_info || addr || negative;
}
static size_t
@ -343,7 +347,7 @@ nsHostRecord::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
n += SizeOfResolveHostCallbackListExcludingHead(&callbacks, mallocSizeOf);
n += addr_info ? addr_info->SizeOfIncludingThis(mallocSizeOf) : 0;
n += mallocSizeOf(addr.get());
n += mallocSizeOf(addr);
n += mBlacklistedItems.ShallowSizeOfExcludingThis(mallocSizeOf);
for (size_t i = 0; i < mBlacklistedItems.Length(); i++) {
@ -803,8 +807,8 @@ nsHostResolver::ResolveHost(const char *host,
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.reset(new NetAddr());
PRNetAddrToNetAddr(&tempAddr, he->rec->addr.get());
he->rec->addr = new NetAddr();
PRNetAddrToNetAddr(&tempAddr, he->rec->addr);
// put reference to host record on stack...
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
METHOD_LITERAL);
@ -866,9 +870,9 @@ 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.reset(new AddrInfo(
unspecHe->rec->addr_info->mHostName.get(),
unspecHe->rec->addr_info->mCanonicalName.get()));
he->rec->addr_info = new AddrInfo(
unspecHe->rec->addr_info->mHostName,
unspecHe->rec->addr_info->mCanonicalName);
he->rec->CopyExpirationTimesAndFlagsFrom(unspecHe->rec);
}
he->rec->addr_info->AddAddress(
@ -1218,7 +1222,7 @@ different_rrset(AddrInfo *rrset1, AddrInfo *rrset2)
return true;
}
LOG(("different_rrset %s\n", rrset1->mHostName.get()));
LOG(("different_rrset %s\n", rrset1->mHostName));
nsTArray<NetAddr> orderedSet1;
nsTArray<NetAddr> orderedSet2;
@ -1285,24 +1289,27 @@ nsHostResolver::OnLookupComplete(nsHostRecord* rec, nsresult status, AddrInfo* n
// 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)) {
if (different_rrset(rec->addr_info, newRRSet)) {
LOG(("nsHostResolver record %p new gencnt\n", rec));
rec->addr_info.reset(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;
}
delete newRRSet;
old_addr_info = newRRSet;
}
}
delete old_addr_info;
rec->negative = !rec->addr_info;
PrepareRecordExpiration(rec);
rec->resolving = false;
if (rec->usingAnyThread) {
mActiveAnyThreadCount--;
rec->usingAnyThread = false;

Просмотреть файл

@ -21,7 +21,6 @@
#include "mozilla/net/DNS.h"
#include "mozilla/net/DashboardTypes.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
class nsHostResolver;
class nsHostRecord;
@ -74,8 +73,8 @@ public:
*/
Mutex addr_info_lock;
int addr_info_gencnt; /* generation count of |addr_info| */
mozilla::UniquePtr<mozilla::net::AddrInfo> addr_info;
mozilla::UniquePtr<mozilla::net::NetAddr> addr;
mozilla::net::AddrInfo *addr_info;
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