From d1e820d8ee01583e1db13ff27ec32dc94e18641d Mon Sep 17 00:00:00 2001 From: NanXiao Date: Mon, 14 Jul 2014 14:33:16 +0800 Subject: [PATCH] Add error check in redisContextInit Check whether the obuf or reader is empty: if one of the items is empty, free the redisContext. --- hiredis.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hiredis.c b/hiredis.c index 10ac8d0..a36c6f3 100644 --- a/hiredis.c +++ b/hiredis.c @@ -1059,6 +1059,12 @@ static redisContext *redisContextInit(void) { c->errstr[0] = '\0'; c->obuf = sdsempty(); c->reader = redisReaderCreate(); + + if (c->obuf == NULL || c->reader == NULL) { + redisFree(c); + return NULL; + } + return c; }