From 9c36f3afa29fad75bcdf56642a81eeaa73cbc5d5 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 4 Oct 2021 21:20:16 +0200 Subject: [PATCH] Add zalloc --- core/alloc.c | 9 +++++++++ core/alloc.h | 1 + 2 files changed, 10 insertions(+) diff --git a/core/alloc.c b/core/alloc.c index d7414b6..491ac24 100644 --- a/core/alloc.c +++ b/core/alloc.c @@ -304,6 +304,15 @@ void *malloc(size_t size) return ret; } +void *zalloc(size_t size){ + void *alloc = malloc(size); + + if (alloc != NULL) + memset(alloc, 0, size); + + return alloc; +} + static int freeFromSlab(void *ptr, struct slabEntry *slab) { struct slabEntry *slabEntry; diff --git a/core/alloc.h b/core/alloc.h index 176f7a1..944bf7c 100644 --- a/core/alloc.h +++ b/core/alloc.h @@ -15,6 +15,7 @@ int allocPopulate(); int allocBookSlab(size_t size, size_t sizeSlab, int selfContained); void *malloc(size_t size); +void *zalloc(size_t size); void free(void *ptr); /* Stuct definition shared for test purpose