From ba8b89a1549c5ce7d7544813c9137798de454fac Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Mon, 18 Sep 2017 20:53:49 +0300 Subject: [PATCH] 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 --- lib/memalign.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; -- 2.25.1