PATCH: Make chunk size a multiple of MALLOC_ALIGNMENT
Carlos O'Donell
carlos@systemhalted.org
Fri May 25 01:40:00 GMT 2012
On Thu, May 24, 2012 at 8:36 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> This bug caused some test failures in one of nss packages on Linux/x32.
>>> This patch fixes it. OK to install?
>>
>> Why doesn't this trigger for any other architectures?
>
> It is very rare, even with MALLOC_ALIGNMENT. > (2*SIZE_SZ).
> I only saw it once on Linux/x32.
Why is it rare? Is it because it's a combination of alloc's and free's
that end up with an old_top that doesn't have the right size?
It looks like a generic issue... but it just isn't triggered by anyone... yet.
>>> set_head(chunk_at_offset(old_top, old_size + 2*SIZE_SZ), 0|PREV_INUSE);
>>> if (old_size >= MINSIZE) {
>>> set_head(chunk_at_offset(old_top, old_size), (2*SIZE_SZ)|PREV_INUSE);
>>> @@ -3803,8 +3804,10 @@ _int_free(mstate av, mchunkptr p, int have_lock)
>>> malloc_printerr (check_action, errstr, chunk2mem(p));
>>> return;
>>> }
>>> - /* We know that each chunk is at least MINSIZE bytes in size. */
>>> - if (__builtin_expect (size < MINSIZE, 0))
>>> + /* We know that each chunk is at least MINSIZE bytes in size of a
>>> + multiple of MALLOC_ALIGNMENT. */
>>
>> Should e "or a" not "of a"?
>
> Fixed.
>
>>> + if (__builtin_expect (size < MINSIZE
>>> + || (size & MALLOC_ALIGN_MASK) != 0, 0))
>>
>> Should this use aligned_OK?
>>
>> The aligned_OK macro should be used in a lot more places :-(
>>
>
> Fixed. Here is the updated patch. OK to install?
This looks good to me.
Please check this in.
Cheers,
Carlos.
More information about the Libc-alpha
mailing list