am 1ff91085: am 52e7d3d9: Bulletproof leak dump against null hash entries
Merge commit '1ff910858c8ae5863761101c673a196a6a16bca3' * commit '1ff910858c8ae5863761101c673a196a6a16bca3': Bulletproof leak dump against null hash entries
This commit is contained in:
commit
caaf7ecd1c
@ -60,34 +60,43 @@ HashTable gHashTable;
|
|||||||
|
|
||||||
static int hash_entry_compare(const void* arg1, const void* arg2)
|
static int hash_entry_compare(const void* arg1, const void* arg2)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
HashEntry* e1 = *(HashEntry**)arg1;
|
HashEntry* e1 = *(HashEntry**)arg1;
|
||||||
HashEntry* e2 = *(HashEntry**)arg2;
|
HashEntry* e2 = *(HashEntry**)arg2;
|
||||||
|
|
||||||
size_t nbAlloc1 = e1->allocations;
|
// if one or both arg pointers are null, deal gracefully
|
||||||
size_t nbAlloc2 = e2->allocations;
|
if (e1 == NULL) {
|
||||||
size_t size1 = e1->size & ~SIZE_FLAG_MASK;
|
result = (e2 == NULL) ? 0 : 1;
|
||||||
size_t size2 = e2->size & ~SIZE_FLAG_MASK;
|
} else if (e2 == NULL) {
|
||||||
size_t alloc1 = nbAlloc1 * size1;
|
|
||||||
size_t alloc2 = nbAlloc2 * size2;
|
|
||||||
|
|
||||||
// sort in descending order by:
|
|
||||||
// 1) total size
|
|
||||||
// 2) number of allocations
|
|
||||||
//
|
|
||||||
// This is used for sorting, not determination of equality, so we don't
|
|
||||||
// need to compare the bit flags.
|
|
||||||
int result;
|
|
||||||
if (alloc1 > alloc2) {
|
|
||||||
result = -1;
|
result = -1;
|
||||||
} else if (alloc1 < alloc2) {
|
|
||||||
result = 1;
|
|
||||||
} else {
|
} else {
|
||||||
if (nbAlloc1 > nbAlloc2) {
|
size_t nbAlloc1 = e1->allocations;
|
||||||
|
size_t nbAlloc2 = e2->allocations;
|
||||||
|
size_t size1 = e1->size & ~SIZE_FLAG_MASK;
|
||||||
|
size_t size2 = e2->size & ~SIZE_FLAG_MASK;
|
||||||
|
size_t alloc1 = nbAlloc1 * size1;
|
||||||
|
size_t alloc2 = nbAlloc2 * size2;
|
||||||
|
|
||||||
|
// sort in descending order by:
|
||||||
|
// 1) total size
|
||||||
|
// 2) number of allocations
|
||||||
|
//
|
||||||
|
// This is used for sorting, not determination of equality, so we don't
|
||||||
|
// need to compare the bit flags.
|
||||||
|
int result;
|
||||||
|
if (alloc1 > alloc2) {
|
||||||
result = -1;
|
result = -1;
|
||||||
} else if (nbAlloc1 < nbAlloc2) {
|
} else if (alloc1 < alloc2) {
|
||||||
result = 1;
|
result = 1;
|
||||||
} else {
|
} else {
|
||||||
result = 0;
|
if (nbAlloc1 > nbAlloc2) {
|
||||||
|
result = -1;
|
||||||
|
} else if (nbAlloc1 < nbAlloc2) {
|
||||||
|
result = 1;
|
||||||
|
} else {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user