From bef7086f20277619e8d3fad0d4230f5675e2ef78 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Fri, 15 Nov 2013 22:40:46 +0100 Subject: [PATCH] libc: fix size calculation in 'Mem_alloc_impl::alloc' When allocating new backing store in 'Mem_alloc_impl::alloc()', the requested alignment needs to be considered in the size calculation. Fixes #973. --- libports/src/lib/libc/libc_mem_alloc.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libports/src/lib/libc/libc_mem_alloc.cc b/libports/src/lib/libc/libc_mem_alloc.cc index 804b3fe7c..19ba2796a 100644 --- a/libports/src/lib/libc/libc_mem_alloc.cc +++ b/libports/src/lib/libc/libc_mem_alloc.cc @@ -187,10 +187,11 @@ void *Libc::Mem_alloc_impl::alloc(size_t size, size_t align_log2) /* * Calculate block size of needed backing store. The block must hold the - * requested 'size' and a new Dataspace structure if the allocation above - * failed. Finally, we align the size to a 4K page. + * requested 'size' with the requested alignment and a new Dataspace + * structure if the allocation above failed. + * Finally, we align the size to a 4K page. */ - size_t request_size = size + 1024; + size_t request_size = size + max((1 << align_log2), 1024); if (request_size < _chunk_size*sizeof(umword_t)) { request_size = _chunk_size*sizeof(umword_t);