You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hiredis/78cec256efa5ca4705af85edbdf...

56 lines
1.6 KiB

From 78cec256efa5ca4705af85edbdf137060c9a4b0a Mon Sep 17 00:00:00 2001
From: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sun, 19 Jan 2020 11:49:13 +0000
Subject: [PATCH] Abort if malloc() was unsuccessful. (Closes: #747)
---
async.c | 2 ++
dict.c | 7 ++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/async.c b/async.c
index 4f422d566..f9193dd05 100644
--- a/async.c
+++ b/async.c
@@ -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;
}
diff --git a/dict.c b/dict.c
index 5b349f078..70ef57f6b 100644
--- a/dict.c
+++ b/dict.c
@@ -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;
}
@@ -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;
@@ -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;