From 669ac9d0c843f9ccf07d4969ff6bff75fafee01f Mon Sep 17 00:00:00 2001 From: Michael Grunder Date: Tue, 28 Jan 2020 12:13:05 -0800 Subject: Safe allocation wrappers (#754) Create allocation wrappers with a configurable OOM handler (defaults to abort()). See #752, #747 --- dict.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'dict.c') diff --git a/dict.c b/dict.c index 5b349f0..eaf4e4d 100644 --- a/dict.c +++ b/dict.c @@ -34,6 +34,7 @@ */ #include "fmacros.h" +#include "alloc.h" #include #include #include @@ -71,7 +72,7 @@ static void _dictReset(dict *ht) { /* Create a new hash table */ static dict *dictCreate(dictType *type, void *privDataPtr) { - dict *ht = malloc(sizeof(*ht)); + dict *ht = hi_malloc(sizeof(*ht)); _dictInit(ht,type,privDataPtr); return ht; } @@ -142,7 +143,7 @@ static int dictAdd(dict *ht, void *key, void *val) { return DICT_ERR; /* Allocates the memory and stores key */ - entry = malloc(sizeof(*entry)); + entry = hi_malloc(sizeof(*entry)); entry->next = ht->table[index]; ht->table[index] = entry; @@ -256,7 +257,7 @@ static dictEntry *dictFind(dict *ht, const void *key) { } static dictIterator *dictGetIterator(dict *ht) { - dictIterator *iter = malloc(sizeof(*iter)); + dictIterator *iter = hi_malloc(sizeof(*iter)); iter->ht = ht; iter->index = -1; -- cgit v1.2.3