[osx] unbreak EmergencyMallocNoHook test

OSX's malloc zones stuff is essentially incompatible with emergency
malloc. In order to handle it, our unit tests use tc_free directly in
order to free memory allocated by emergency malloc. So lets keep doing
it for our newer code that exercises calloc/free pair as well.
This commit is contained in:
Aliaksei Kandratsenka 2024-09-16 13:11:23 -04:00
parent 92fd07cc2f
commit a4e2f95038
2 changed files with 4 additions and 1 deletions

View File

@ -108,6 +108,9 @@ extern "C" {
// We need to provide wrappers around all the libc functions.
namespace {
size_t mz_size(malloc_zone_t* zone, const void* ptr) {
// Note, this does not work for emergency malloc's memory. And in
// principle OSX doesn't need or use it. But by default we enable
// it, so that our unit test coverage is wider.
if (MallocExtension::instance()->GetOwnership(ptr) != MallocExtension::kOwned)
return 0; // malloc_zone semantics: return 0 if we don't own the memory

View File

@ -1609,7 +1609,7 @@ TEST(TCMallocTest, EmergencyMallocNoHook) {
portal->WithEmergencyMallocEnabled([&] () {
p2 = noopt(malloc)(32);
for (int i = 11; i < 999; i++) {
free(p3);
tc_free(p3);
p3 = tc_calloc(1, i);
}
p4 = tc_calloc(4096, 1024);