Make zone_{free, realloc, free_definite_size} fallback to the system allocator if they are called with a pointer that jemalloc didn't allocate
It turns out some OSX system libraries (like CoreGraphics on 10.6) like to call malloc_zone_* functions, but giving them pointers that weren't allocated with the zone they are using. Possibly, they do malloc_zone_malloc(malloc_default_zone()) before we register the jemalloc zone, and malloc_zone_realloc(malloc_default_zone()) after. malloc_default_zone() returning a different value in both cases.
This commit is contained in:
parent
5c89c50d18
commit
5b3db098f7
21
src/zone.c
21
src/zone.c
@ -80,14 +80,22 @@ static void
|
|||||||
zone_free(malloc_zone_t *zone, void *ptr)
|
zone_free(malloc_zone_t *zone, void *ptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
je_free(ptr);
|
if (ivsalloc(ptr) != 0) {
|
||||||
|
je_free(ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
zone_realloc(malloc_zone_t *zone, void *ptr, size_t size)
|
zone_realloc(malloc_zone_t *zone, void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (je_realloc(ptr, size));
|
if (ivsalloc(ptr) != 0)
|
||||||
|
return (je_realloc(ptr, size));
|
||||||
|
|
||||||
|
return (realloc(ptr, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (JEMALLOC_ZONE_VERSION >= 5)
|
#if (JEMALLOC_ZONE_VERSION >= 5)
|
||||||
@ -107,8 +115,13 @@ static void
|
|||||||
zone_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size)
|
zone_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
assert(ivsalloc(ptr) == size);
|
if (ivsalloc(ptr) != 0) {
|
||||||
je_free(ptr);
|
assert(ivsalloc(ptr) == size);
|
||||||
|
je_free(ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user