[PATCH 2/2] Avoid crashes when system libraries use the purgeable zone allocator
Justin Lebar
justin.lebar at gmail.com
Tue Mar 27 09:20:53 PDT 2012
+ * [...] This
+ * obviously fails when the default zone is the jemalloc zone, so
+ * malloc_default_purgeable_zone is called beforehand so that the
+ * default purgeable zone is create when the default zone is still
+ * a scalable_zone.
Nit: s/create/created
+ * As purgeable zones only exist on >= 10.6, we need to check for the
+ * function existence at runtime.
Nit: s/function/function's
On Tue, Mar 27, 2012 at 5:20 AM, Mike Hommey <mh+jemalloc at glandium.org> wrote:
> From: Mike Hommey <mh at glandium.org>
>
> ---
> src/zone.c | 21 +++++++++++++++++++++
> 1 files changed, 21 insertions(+), 0 deletions(-)
>
> diff --git a/src/zone.c b/src/zone.c
> index 4b6c75e..d5eae46 100644
> --- a/src/zone.c
> +++ b/src/zone.c
> @@ -3,6 +3,13 @@
> # error "This source file is for zones on Darwin (OS X)."
> #endif
>
> +/*
> + * The malloc_default_purgeable_zone function is only available on >= 10.6.
> + * We need to check whether it is present at runtime, thus the weak_import.
> + */
> +extern malloc_zone_t *malloc_default_purgeable_zone(void)
> +JEMALLOC_ATTR(weak_import);
> +
> /******************************************************************************/
> /* Data. */
>
> @@ -207,6 +214,20 @@ register_zone(void)
> #endif
> #endif
>
> + /*
> + * The default purgeable zone is created lazily by OSX's libc. It uses
> + * the default zone when it is created for "small" allocations
> + * (< 15 KiB), but assumes the default zone is a scalable_zone. This
> + * obviously fails when the default zone is the jemalloc zone, so
> + * malloc_default_purgeable_zone is called beforehand so that the
> + * default purgeable zone is create when the default zone is still
> + * a scalable_zone.
> + * As purgeable zones only exist on >= 10.6, we need to check for the
> + * function existence at runtime.
> + */
> + if (malloc_default_purgeable_zone)
> + malloc_default_purgeable_zone();
> +
> /* Register the custom zone. At this point it won't be the default. */
> malloc_zone_register(&zone);
>
> --
> 1.7.9.1
>
> _______________________________________________
> jemalloc-discuss mailing list
> jemalloc-discuss at canonware.com
> http://www.canonware.com/mailman/listinfo/jemalloc-discuss
More information about the jemalloc-discuss
mailing list