Skip to content

Commit 1af7c8d

Browse files
committed
[CF] Do not call malloc_size unless debugging.
CFBasicHashGetSize has an argument, total, to enable whether to presumably calculate the size its dependent data structures. CFBasicHashGetSize does not appear outside CFBasicHash.c, and this total argument is true only when ENABLE_MEMORY_COUNTERS is true or transitively when ENABLE_DTRACE_PROBES is true. These preprocessor symbols appear to be to control debugging and other informational purposes. malloc introspection, as afforded by malloc_size, malloc_usable_size, or msize, is nonportable (and thus not guaranteed to be present on all platforms), not guaranteed to be accurate (though certainly an upper bound), and is generally recommended for debugging. For those reasons, only expose the call to malloc_size when either of ENABLE_MEMORY_COUNTERS or ENABLE_DTRACE_PROBES is true. This avoids an undefined symbol issue when malloc introspection is unavailable, but does mean these counters and other information is not available on platforms when malloc_size is not present.
1 parent c354f55 commit 1af7c8d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

CoreFoundation/Collections.subproj/CFBasicHash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ CF_PRIVATE size_t CFBasicHashGetSize(CFConstBasicHashRef ht, Boolean total) {
14421442
if (ht->bits.keys_offset) size += sizeof(CFBasicHashValue *);
14431443
if (ht->bits.counts_offset) size += sizeof(void *);
14441444
if (__CFBasicHashHasHashCache(ht)) size += sizeof(uintptr_t *);
1445+
#if ENABLE_MEMORY_COUNTERS || ENABLE_DTRACE_PROBES
14451446
if (total) {
14461447
CFIndex num_buckets = __CFBasicHashTableSizes[ht->bits.num_buckets_idx];
14471448
if (0 < num_buckets) {
@@ -1451,6 +1452,9 @@ CF_PRIVATE size_t CFBasicHashGetSize(CFConstBasicHashRef ht, Boolean total) {
14511452
if (__CFBasicHashHasHashCache(ht)) size += malloc_size(__CFBasicHashGetHashes(ht));
14521453
}
14531454
}
1455+
#else
1456+
(void)total;
1457+
#endif
14541458
return size;
14551459
}
14561460

0 commit comments

Comments
 (0)