summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanXiao <xn212516@163.com>2014-07-14 14:33:16 +0800
committerMatt Stancliff <matt@genges.com>2015-01-05 16:39:30 -0500
commitd1e820d8ee01583e1db13ff27ec32dc94e18641d (patch)
treeeecb574655bed6a701a0a22f139603e7f690dabc
parentb6a860795c0c97c59c79155640531b8c47c34ea3 (diff)
downloadhiredict-d1e820d8ee01583e1db13ff27ec32dc94e18641d.tar.xz
Add error check in redisContextInit
Check whether the obuf or reader is empty: if one of the items is empty, free the redisContext.
-rw-r--r--hiredis.c6
1 files changed, 6 insertions, 0 deletions
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;
}