about summary refs log tree commit diff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-09-08 15:36:50 -0700
committerH.J. Lu <hjl.tools@gmail.com>2012-09-09 11:26:25 -0700
commit5362c04ba6d076dd02b990f98270b6e20a65f7df (patch)
treeaa507b7b2118007ca128d2b9ad0579059745001a
parent5b489807f7c8902901b42451883f3d5c89616a8a (diff)
downloadglibc-hjl/pr14562/2.16.tar.gz
glibc-hjl/pr14562/2.16.tar.xz
glibc-hjl/pr14562/2.16.zip
Properly handle fencepost with MALLOC_ALIGN_MASK hjl/pr14562/2.16
-rw-r--r--ChangeLog.pr145625
-rw-r--r--malloc/arena.c7
2 files changed, 10 insertions, 2 deletions
diff --git a/ChangeLog.pr14562 b/ChangeLog.pr14562
new file mode 100644
index 0000000000..b92843d223
--- /dev/null
+++ b/ChangeLog.pr14562
@@ -0,0 +1,5 @@
+2012-09-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+	[BZ #14562]
+	* malloc/arena.c (heap_trim): Properly get fencepost and adjust
+	new chunk size with MALLOC_ALIGN_MASK.
diff --git a/malloc/arena.c b/malloc/arena.c
index 33c4ff37a7..399c1e472f 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -652,15 +652,18 @@ heap_trim(heap_info *heap, size_t pad)
   unsigned long pagesz = GLRO(dl_pagesize);
   mchunkptr top_chunk = top(ar_ptr), p, bck, fwd;
   heap_info *prev_heap;
-  long new_size, top_size, extra;
+  long new_size, top_size, extra, misalign;
 
   /* Can this heap go away completely? */
   while(top_chunk == chunk_at_offset(heap, sizeof(*heap))) {
     prev_heap = heap->prev;
     p = chunk_at_offset(prev_heap, prev_heap->size - (MINSIZE-2*SIZE_SZ));
+    /* fencepost must be properly aligned.  */
+    misalign = ((long) p) & MALLOC_ALIGN_MASK;
+    p = (mchunkptr)(((unsigned long) p) & ~MALLOC_ALIGN_MASK);
     assert(p->size == (0|PREV_INUSE)); /* must be fencepost */
     p = prev_chunk(p);
-    new_size = chunksize(p) + (MINSIZE-2*SIZE_SZ);
+    new_size = chunksize(p) + (MINSIZE-2*SIZE_SZ) + misalign;
     assert(new_size>0 && new_size<(long)(2*MINSIZE));
     if(!prev_inuse(p))
       new_size += p->prev_size;