This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/12495] Malloc fails if MALLOC_ALIGNMENT > 2 * SIZE_SZ


http://sourceware.org/bugzilla/show_bug.cgi?id=12495

--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> 2011-03-02 05:17:21 UTC ---
(In reply to comment #3)
> (In reply to comment #1)
> > On Thu, 17 Feb 2011, hjl.tools at gmail dot com wrote:
> > 
> > > If I define  MALLOC_ALIGNMENT > 2 * SIZE_SZ, malloc will
> > > fail in mysterious ways.
> > 
> > Yes, this is known.  There's a patch at 
> > <http://sourceware.org/ml/libc-alpha/2007-11/msg00062.html> that fixes the 
> > problem in the context of PowerPC malloc not allocating memory 
> > sufficiently aligned for long double.
> 
> Unfortunately, this patch is incorrect.  This code
> 
>           front_misalign = (INTERNAL_SIZE_T)chunk2mem(brk) & MALLOC_ALIGN_MASK;
>           if (front_misalign > 0) { 
> 
>             /*   
>               Skip over some bytes to arrive at an aligned position.
>               We don't need to specially mark these wasted front bytes.
>               They will never be accessed anyway because
>               prev_inuse of av->top (and any chunk created from its start)
>               is always true after initialization.
>             */
> 
>             correction = MALLOC_ALIGNMENT - front_misalign;
>             aligned_brk += correction;
>           }    
> 
> misaligns memory when
> 
> 1. MALLOC_ALIGNMENT == 16
> 2. front_misalign == 8
> 3. aligned_brk == brk == 0xf7b61000

I am testing this patch:

diff --git a/malloc/malloc.c b/malloc/malloc.c
index c4bc1fb..f8acd66 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3370,8 +3370,7 @@ static Void_t* sYSMALLOc(nb, av) INTERNAL_SIZE_T nb;
mstat
e av;
           is always true after initialization.
         */

-        correction = MALLOC_ALIGNMENT - front_misalign;
-        aligned_brk += correction;
+        aligned_brk += MALLOC_ALIGNMENT - front_misalign;
       }
     }

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]