summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2012-03-26 16:39:35 (GMT)
committerJason Evans <jasone@canonware.com>2012-03-26 19:54:25 (GMT)
commit5b3db098f73f467a03f87a2242c692268f796a56 (patch)
tree7b5110b23a9fa5c6a43d112f11b4c7dd1ff58af2 /src
parent5c89c50d1803dc0fb6544c1abd40552e76c8614d (diff)
downloadjemalloc-5b3db098f73f467a03f87a2242c692268f796a56.zip
jemalloc-5b3db098f73f467a03f87a2242c692268f796a56.tar.gz
jemalloc-5b3db098f73f467a03f87a2242c692268f796a56.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/zone.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/zone.c b/src/zone.c
index a8f09c9..d3107f8 100644
--- a/src/zone.c
+++ b/src/zone.c
@@ -80,14 +80,22 @@ static void
zone_free(malloc_zone_t *zone, void *ptr)
{
- je_free(ptr);
+ if (ivsalloc(ptr) != 0) {
+ je_free(ptr);
+ return;
+ }
+
+ free(ptr);
}
static void *
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)
@@ -107,8 +115,13 @@ static void
zone_free_definite_size(malloc_zone_t *zone, void *ptr, size_t size)
{
- assert(ivsalloc(ptr) == size);
- je_free(ptr);
+ if (ivsalloc(ptr) != 0) {
+ assert(ivsalloc(ptr) == size);
+ je_free(ptr);
+ return;
+ }
+
+ free(ptr);
}
#endif