From 9219556386a928f86ef38a36b081c7cf42d5e87a Mon Sep 17 00:00:00 2001 From: "cdliuqiang@gmail.com" Date: Wed, 16 Aug 2017 12:36:35 +0800 Subject: calloc param fixes and NULL check --- hiredis.c | 4 ++++ read.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hiredis.c b/hiredis.c index 3a7ab11..b344962 100644 --- a/hiredis.c +++ b/hiredis.c @@ -710,6 +710,8 @@ redisContext *redisConnectNonBlock(const char *ip, int port) { redisContext *redisConnectBindNonBlock(const char *ip, int port, const char *source_addr) { redisContext *c = redisContextInit(); + if (c == NULL) + return NULL; c->flags &= ~REDIS_BLOCK; redisContextConnectBindTcp(c,ip,port,NULL,source_addr); return c; @@ -718,6 +720,8 @@ redisContext *redisConnectBindNonBlock(const char *ip, int port, redisContext *redisConnectBindNonBlockWithReuse(const char *ip, int port, const char *source_addr) { redisContext *c = redisContextInit(); + if (c == NULL) + return NULL; c->flags &= ~REDIS_BLOCK; c->flags |= REDIS_REUSEADDR; redisContextConnectBindTcp(c,ip,port,NULL,source_addr); diff --git a/read.c b/read.c index 50333b5..061bbda 100644 --- a/read.c +++ b/read.c @@ -416,7 +416,7 @@ static int processItem(redisReader *r) { redisReader *redisReaderCreateWithFunctions(redisReplyObjectFunctions *fn) { redisReader *r; - r = calloc(sizeof(redisReader),1); + r = calloc(1,sizeof(redisReader)); if (r == NULL) return NULL; -- cgit v1.2.3