aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-11-14 23:15:31 +0100
committerMattias Andrée <maandree@operamail.com>2015-11-14 23:15:31 +0100
commit598f047f2857dd793d0a4445c77076524382babd (patch)
tree69432f89316ac02f3283f74642dfa390a92c5a03
parentadd mallocz (diff)
downloadslibc-598f047f2857dd793d0a4445c77076524382babd.tar.gz
slibc-598f047f2857dd793d0a4445c77076524382babd.tar.bz2
slibc-598f047f2857dd793d0a4445c77076524382babd.tar.xz
m malloc.c
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/malloc.c16
1 files changed, 12 insertions, 4 deletions
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;
}