diff options
author | Michael Grunder <michael.grunder@gmail.com> | 2020-01-28 12:13:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-28 12:13:05 -0800 |
commit | 669ac9d0c843f9ccf07d4969ff6bff75fafee01f (patch) | |
tree | 6075cb357e13342f6844dc9891d6c3c38c8e6f86 /dict.c | |
parent | 0501c623c91344e54cb2775a91509650960789b1 (diff) |
Safe allocation wrappers (#754)
Create allocation wrappers with a configurable OOM handler (defaults to abort()).
See #752, #747
Diffstat (limited to 'dict.c')
-rw-r--r-- | dict.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -34,6 +34,7 @@ */ #include "fmacros.h" +#include "alloc.h" #include <stdlib.h> #include <assert.h> #include <limits.h> @@ -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; |