Skip to content

Commit

Permalink
Abort if malloc() was unsuccessful. (Closes: redis#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
lamby committed Jan 19, 2020
1 parent 0501c62 commit 78cec25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions async.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static unsigned int callbackHash(const void *key) {
static void *callbackValDup(void *privdata, const void *src) {
((void) privdata);
redisCallback *dup = malloc(sizeof(*dup));
if (dup == NULL)
abort();
memcpy(dup,src,sizeof(*dup));
return dup;
}
Expand Down
7 changes: 6 additions & 1 deletion dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ static void _dictReset(dict *ht) {
/* Create a new hash table */
static dict *dictCreate(dictType *type, void *privDataPtr) {
dict *ht = malloc(sizeof(*ht));
if (ht == NULL)
abort();
_dictInit(ht,type,privDataPtr);
return ht;
}
Expand Down Expand Up @@ -143,6 +145,8 @@ static int dictAdd(dict *ht, void *key, void *val) {

/* Allocates the memory and stores key */
entry = malloc(sizeof(*entry));
if (entry == NULL)
abort();
entry->next = ht->table[index];
ht->table[index] = entry;

Expand Down Expand Up @@ -257,7 +261,8 @@ static dictEntry *dictFind(dict *ht, const void *key) {

static dictIterator *dictGetIterator(dict *ht) {
dictIterator *iter = malloc(sizeof(*iter));

if (iter == NULL)
abort();
iter->ht = ht;
iter->index = -1;
iter->entry = NULL;
Expand Down

0 comments on commit 78cec25

Please sign in to comment.