[patch v1] malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101)
Florian Weimer
fweimer@redhat.com
Tue Apr 4 10:26:32 GMT 2023
* DJ Delorie via Libc-alpha:
> From 61bd502ecac4d63f04c74bfc491ca675660d26b7 Mon Sep 17 00:00:00 2001
> From: DJ Delorie <dj@redhat.com>
> Date: Mon, 3 Apr 2023 17:33:03 -0400
> Subject: malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101)
>
> Based on these comments in malloc.c:
>
> size field is or'ed with NON_MAIN_ARENA if the chunk was obtained
> from a non-main arena. This is only set immediately before handing
> the chunk to the user, if necessary.
>
> The NON_MAIN_ARENA flag is never set for unsorted chunks, so it
> does not have to be taken into account in size comparisons.
>
> When we pull a chunk off the unsorted list (or any list) we need to
> make sure that flag is set properly before returning the chunk.
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 0315ac5d16..66e7ca57dd 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -5147,6 +5147,8 @@ _int_memalign (mstate av, size_t alignment, size_t bytes)
> p = victim;
> m = chunk2mem (p);
> set_inuse (p);
> + if (av != &main_arena)
> + set_non_main_arena (p);
> }
> else
> {
The change looks reasonable.
Can we add a test for this? Maybe run the existing memalign tests on a
second thread as well?
Thanks,
Florian
More information about the Libc-alpha
mailing list