Check malloc return value

This commit is contained in:
Mathieu Maret 2021-03-22 22:48:23 +01:00
parent 12cf6b1f89
commit a2d2e1de60

View File

@ -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); ((*desc)->slab).freeEl = (char *)(*desc) + sizeof(struct slabDesc);
} else { } else {
*desc = malloc(sizeof(struct slabDesc)); *desc = malloc(sizeof(struct slabDesc));
if (*desc == NULL)
return -ENOMEM;
(*desc)->slab.freeEl = (void *)alloc; (*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); (*desc)->freeEl = (char *)(*desc) + sizeof(struct slabEntry);
} else { } else {
*desc = malloc(sizeof(struct slabEntry)); *desc = malloc(sizeof(struct slabEntry));
if (*desc == NULL)
return -ENOMEM;
(*desc)->freeEl = (void *)alloc; (*desc)->freeEl = (void *)alloc;
} }