diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-09-19 19:01:31 +0200 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-09-19 19:01:31 +0200 |
commit | 62c8054dbe5d590a7f2d36e4e5176996215e9aa7 (patch) | |
tree | 2a194ad7bf812dbb300f3084614ae6a4bc7e0fef /hiredis.c | |
parent | 457cdbf7c5f98c7ac5b4d727a1bad0c041f7cc66 (diff) |
Clean up when there is an I/O error
Diffstat (limited to 'hiredis.c')
-rw-r--r-- | hiredis.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -73,7 +73,7 @@ redisReply *redisConnect(int *fd, const char *ip, int port) { /* Create a reply object */ static redisReply *createReplyObject(int type, sds reply) { - redisReply *r = malloc(sizeof(*r)); + redisReply *r = calloc(sizeof(*r),1); if (!r) redisOOM(); r->type = type; @@ -94,7 +94,8 @@ void freeReplyObject(redisReply *r) { free(r->element); break; default: - sdsfree(r->reply); + if (r->reply != NULL) + sdsfree(r->reply); break; } free(r); @@ -303,8 +304,13 @@ static redisReply *redisReadReply(int fd) { } /* read from socket into buffer */ - if ((bytes = read(fd,r.buf+r.avail,READ_BUFFER_SIZE)) <= 0) + if ((bytes = read(fd,r.buf+r.avail,READ_BUFFER_SIZE)) <= 0) { + /* rlist[0] is the "root" reply object */ + freeReplyObject(r.rlist[0]); + free(r.buf); + free(r.rlist); return redisIOError(); + } r.avail += bytes; r.buf[r.avail] = '\0'; |