Skip to content

Commit

Permalink
Don't register jemalloc's zone allocator if something else already re…
Browse files Browse the repository at this point in the history
…placed the system default zone
  • Loading branch information
glandium authored and Jason Evans committed Nov 7, 2012
1 parent e3d1306 commit 847ff22
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ void
register_zone(void)
{

/*
* If something else replaced the system default zone allocator, don't
* register jemalloc's.
*/
malloc_zone_t *default_zone = malloc_default_zone();
if (!default_zone->zone_name ||
strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) {
return;
}

zone.size = (void *)zone_size;
zone.malloc = (void *)zone_malloc;
zone.calloc = (void *)zone_calloc;
Expand Down Expand Up @@ -241,7 +251,7 @@ register_zone(void)
* then becomes the default.
*/
do {
malloc_zone_t *default_zone = malloc_default_zone();
default_zone = malloc_default_zone();
malloc_zone_unregister(default_zone);
malloc_zone_register(default_zone);
} while (malloc_default_zone() != &zone);
Expand Down

0 comments on commit 847ff22

Please sign in to comment.