From 598f047f2857dd793d0a4445c77076524382babd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 14 Nov 2015 23:15:31 +0100 Subject: m malloc.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/malloc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/malloc.c b/src/malloc.c index 864a8f5..538f338 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -31,6 +31,11 @@ /* } */ +/** + * Implementation of `malloc`. + */ +#define MALLOC(size) memalign(sizeof(max_align_t), size) + /** * Create a new memory allocation on the heap. @@ -84,7 +89,7 @@ static void* unaligned_malloc(size_t size) */ void* malloc(size_t size) { - return memalign(sizeof(max_align_t), size); + return MALLOC(size); } @@ -113,7 +118,7 @@ void* calloc(size_t elem_count, size_t elem_size) if (__builtin_umull_overflow(elem_count, elem_size, &size)) return errno = ENOMEM, NULL; - ptr = malloc(size); + ptr = MALLOC(size); if (ptr != NULL) explicit_bzero(ptr, size); @@ -139,7 +144,7 @@ void* calloc(size_t elem_count, size_t elem_size) */ void* mallocz(size_t size, int clear) { - void* ptr = memalign(sizeof(max_align_t), size); + void* ptr = MALLOC(size); if ((ptr != NULL) && clear) explicit_bzero(ptr, size); return ptr; @@ -167,7 +172,10 @@ void* mallocz(size_t size, int clear) */ void* zalloc(size_t size) { - return calloc(1, size); + void* ptr = MALLOC(size); + if (ptr != NULL) + explicit_bzero(ptr, size); + return ptr; } -- cgit v1.2.3-70-g09d2