From a2d2e1de602cc6d103a5e1fa6c4a872cee3cd331 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 22 Mar 2021 22:48:23 +0100 Subject: [PATCH] Check malloc return value --- core/alloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/alloc.c b/core/alloc.c index bfa5517..6b08a7c 100644 --- a/core/alloc.c +++ b/core/alloc.c @@ -126,6 +126,8 @@ static int allocSlab(struct slabDesc **desc, size_t size, size_t sizeSlab, int s ((*desc)->slab).freeEl = (char *)(*desc) + sizeof(struct slabDesc); } else { *desc = malloc(sizeof(struct slabDesc)); + if (*desc == NULL) + return -ENOMEM; (*desc)->slab.freeEl = (void *)alloc; } @@ -174,6 +176,8 @@ static int allocSlabEntry(struct slabEntry **desc, size_t size, size_t sizeSlab, (*desc)->freeEl = (char *)(*desc) + sizeof(struct slabEntry); } else { *desc = malloc(sizeof(struct slabEntry)); + if (*desc == NULL) + return -ENOMEM; (*desc)->freeEl = (void *)alloc; }