lib/memalign: don't malloc size twice
authorTomohiro Kusumi <tkusumi@tuxera.com>
Mon, 18 Sep 2017 17:53:49 +0000 (20:53 +0300)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Sep 2017 18:04:36 +0000 (12:04 -0600)
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 <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/memalign.c

index 137cc8ec3ec4eef920b9524c9b6a374cba32660f..bfbd1e80c851da90410dfbf0565849ce725f3193 100644 (file)
@@ -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;