Bug 1309051 - Ensure GetSerialNumber is consistent with aCreate. r=froydnj
MozReview-Commit-ID: 92N6vcV2NhP
--- a/xpcom/base/nsTraceRefcnt.cpp
+++ b/xpcom/base/nsTraceRefcnt.cpp
@@ -569,32 +569,36 @@ LogThisType(const char* aTypeName)
}
static PLHashNumber
HashNumber(const void* aKey)
{
return PLHashNumber(NS_PTR_TO_INT32(aKey));
}
+// This method uses MOZ_RELEASE_ASSERT in the unlikely event that
+// somebody uses this in a non-debug build.
static intptr_t
GetSerialNumber(void* aPtr, bool aCreate)
{
PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers,
HashNumber(aPtr),
aPtr);
if (hep && *hep) {
+ MOZ_RELEASE_ASSERT(!aCreate, "If an object already has a serial number, we should be destroying it.");
return static_cast<SerialNumberRecord*>((*hep)->value)->serialNumber;
- } else if (aCreate) {
- SerialNumberRecord* record = new SerialNumberRecord();
- WalkTheStackSavingLocations(record->allocationStack);
- PL_HashTableRawAdd(gSerialNumbers, hep, HashNumber(aPtr),
- aPtr, static_cast<void*>(record));
- return gNextSerialNumber;
}
- return 0;
+
+ MOZ_RELEASE_ASSERT(aCreate, "If an object does not have a serial number, we should be creating it.");
+
+ SerialNumberRecord* record = new SerialNumberRecord();
+ WalkTheStackSavingLocations(record->allocationStack);
+ PL_HashTableRawAdd(gSerialNumbers, hep, HashNumber(aPtr),
+ aPtr, static_cast<void*>(record));
+ return gNextSerialNumber;
}
static int32_t*
GetRefCount(void* aPtr)
{
PLHashEntry** hep = PL_HashTableRawLookup(gSerialNumbers,
HashNumber(aPtr),
aPtr);