From 5cc7342606dbbd5e6932b39e6b1b5645164669bf Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Tue, 15 Aug 2017 07:56:47 +0200 Subject: Prevent alloc errors from crashing Resolves #76 --- util/list.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'util') diff --git a/util/list.c b/util/list.c index 94159036..279d2ab5 100644 --- a/util/list.c +++ b/util/list.c @@ -6,9 +6,16 @@ list_t *list_create(void) { list_t *list = malloc(sizeof(list_t)); + if (!list) { + return NULL; + } list->capacity = 10; list->length = 0; list->items = malloc(sizeof(void*) * list->capacity); + if (!list->items) { + free(list); + return NULL; + } return list; } -- cgit v1.2.3