diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2012-09-24 08:58:04 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2012-09-24 08:58:04 -0700 |
commit | ced6f16ee919d12725840d43d007f1cfd67118df (patch) | |
tree | 2f861efcccd0eea5dde22744da6c6967ff300532 /malloc | |
parent | a9f8e53a5b14ba481999ded036b025554ea06362 (diff) | |
download | glibc-ced6f16ee919d12725840d43d007f1cfd67118df.tar.gz glibc-ced6f16ee919d12725840d43d007f1cfd67118df.tar.xz glibc-ced6f16ee919d12725840d43d007f1cfd67118df.zip |
Properly handle fencepost with MALLOC_ALIGN_MASK
Diffstat (limited to 'malloc')
-rw-r--r-- | malloc/arena.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/malloc/arena.c b/malloc/arena.c index 97c0b909cc..f24e76c4f6 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -655,15 +655,19 @@ 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, prev_size, 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)); + prev_size = prev_heap->size - (MINSIZE-2*SIZE_SZ); + p = chunk_at_offset(prev_heap, prev_size); + /* fencepost must be properly aligned. */ + misalign = ((long) p) & MALLOC_ALIGN_MASK; + p = chunk_at_offset(prev_heap, prev_size - misalign); 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; |