diff options
-rw-r--r-- | hiredis.c | 11 | ||||
-rw-r--r-- | hiredis.h | 1 | ||||
-rw-r--r-- | test.c | 8 |
3 files changed, 17 insertions, 3 deletions
@@ -586,6 +586,17 @@ static redisContext *redisContextInit(redisReplyFunctions *fn) { return c; } +void redisFree(redisContext *c) { + if (c->error != NULL) + sdsfree(c->error); + if (c->obuf != NULL) + sdsfree(c->obuf); + if (c->clen > 0) + free(c->callbacks); + redisReplyReaderFree(c->reader); + free(c); +} + /* Connect to a Redis instance. On error the field error in the returned * context will be set to the return value of the error function. * When no set of reply functions is given, the default set will be used. */ @@ -103,6 +103,7 @@ int redisReplyReaderGetReply(void *reader, void **reply); redisContext *redisConnect(const char *ip, int port, redisReplyFunctions *fn); redisContext *redisConnectNonBlock(const char *ip, int port, redisReplyFunctions *fn); +void redisFree(redisContext *c); int redisBufferRead(redisContext *c); int redisBufferWrite(redisContext *c, int *done); int redisGetReply(redisContext *c, void **reply); @@ -28,16 +28,17 @@ int main(void) { int i, ret, tests = 0, fails = 0; long long t1, t2; redisContext *c; - redisReply *reply; + redisReply *reply, **replies; void *reader; char *err; - __connect(&c); + __connect(&c); test("Returns I/O error when the connection is lost: "); test_cond(redisCommand(c,"QUIT") == NULL && strcmp(c->error,"Server closed the connection") == 0); - __connect(&c); /* reconnect */ + redisFree(c); + __connect(&c); /* reconnect */ test("Is able to deliver commands: "); reply = redisCommand(c,"PING"); test_cond(reply->type == REDIS_REPLY_STRING && @@ -170,5 +171,6 @@ int main(void) { printf("*** %d TESTS FAILED ***\n", fails); } + redisFree(c); return 0; } |