From: Tomohiro Kusumi Date: Mon, 18 Sep 2017 17:53:49 +0000 (+0300) Subject: lib/memalign: don't malloc size twice X-Git-Tag: fio-3.1~6 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=ba8b89a1549c5ce7d7544813c9137798de454fac;p=fio.git lib/memalign: don't malloc size twice The footer offset (diff between malloc'd address and aligned address) is (alignment-1) at most, and footer appears `size' bytes after the aligned address, thus required size is (alignment-1 + size + sizeof(*f)). The existing code seems to allocate extra unused `size' bytes. Signed-off-by: Tomohiro Kusumi Signed-off-by: Jens Axboe --- diff --git a/lib/memalign.c b/lib/memalign.c index 137cc8ec..bfbd1e80 100644 --- a/lib/memalign.c +++ b/lib/memalign.c @@ -18,7 +18,7 @@ void *fio_memalign(size_t alignment, size_t size) assert(!(alignment & (alignment - 1))); - ptr = malloc(size + alignment + size + sizeof(*f) - 1); + ptr = malloc(size + alignment + sizeof(*f) - 1); if (ptr) { ret = PTR_ALIGN(ptr, alignment - 1); f = ret + size;