From: Mike Hommey <[email protected]>

---
 src/zone.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/zone.c b/src/zone.c
index e0302ef..a722287 100644
--- a/src/zone.c
+++ b/src/zone.c
@@ -176,6 +176,7 @@ register_zone(void)
         * register jemalloc's.
         */
        malloc_zone_t *default_zone = malloc_default_zone();
+       malloc_zone_t *purgeable_zone = NULL;
        if (!default_zone->zone_name ||
            strcmp(default_zone->zone_name, "DefaultMallocZone") != 0) {
                return;
@@ -237,22 +238,37 @@ register_zone(void)
         * run time.
         */
        if (malloc_default_purgeable_zone != NULL)
-               malloc_default_purgeable_zone();
+               purgeable_zone = malloc_default_purgeable_zone();
 
        /* Register the custom zone.  At this point it won't be the default. */
        malloc_zone_register(&zone);
 
-       /*
-        * Unregister and reregister the default zone.  On OSX >= 10.6,
-        * unregistering takes the last registered zone and places it at the
-        * location of the specified zone.  Unregistering the default zone thus
-        * makes the last registered one the default.  On OSX < 10.6,
-        * unregistering shifts all registered zones.  The first registered zone
-        * then becomes the default.
-        */
        do {
                default_zone = malloc_default_zone();
+               /*
+                * Unregister and reregister the default zone.  On OSX >= 10.6,
+                * unregistering takes the last registered zone and places it
+                * at the location of the specified zone.  Unregistering the
+                * default zone thus makes the last registered one the default.
+                * On OSX < 10.6, unregistering shifts all registered zones.
+                * The first registered zone then becomes the default.
+                */
                malloc_zone_unregister(default_zone);
                malloc_zone_register(default_zone);
+               /*
+                * On OSX 10.6, having the default purgeable zone appear before
+                * the default zone makes some things crash because it thinks it
+                * owns the default zone allocated pointers. We thus unregister/
+                * re-register it in order to ensure it's always after the
+                * default zone. On OSX < 10.6, there is no purgeable zone, so
+                * this does nothing. On OSX >= 10.6, unregistering replaces the
+                * purgeable zone with the last registered zone above, i.e the
+                * default zone. Registering it again then puts it at the end,
+                * obviously after the default zone.
+                */
+               if (purgeable_zone) {
+                       malloc_zone_unregister(purgeable_zone);
+                       malloc_zone_register(purgeable_zone);
+               }
        } while (malloc_default_zone() != &zone);
 }
-- 
2.0.0.rc2

_______________________________________________
jemalloc-discuss mailing list
[email protected]
http://www.canonware.com/mailman/listinfo/jemalloc-discuss

Reply via email to