aboutsummaryrefslogtreecommitdiff
path: root/util/list.c
diff options
context:
space:
mode:
authorCalvin Lee <cyrus296@gmail.com>2017-08-15 07:56:47 +0200
committerCalvin Lee <cyrus296@gmail.com>2017-08-15 08:04:57 +0200
commit5cc7342606dbbd5e6932b39e6b1b5645164669bf (patch)
treef4cdef098650e5d0ac2f9ca3237f2f789db1d3fe /util/list.c
parent5ca88af557178c0081fd408ae008686b79d6dd9c (diff)
Prevent alloc errors from crashing
Resolves #76
Diffstat (limited to 'util/list.c')
-rw-r--r--util/list.c7
1 files changed, 7 insertions, 0 deletions
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;
}