summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hiredis.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/hiredis.c b/hiredis.c
index 2d897d5..662bdae 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -594,6 +594,11 @@ void redisDisconnect(redisContext *c) {
}
void redisFree(redisContext *c) {
+ /* Disconnect before free'ing if not yet disconnected. */
+ if (c->flags & REDIS_CONNECTED)
+ redisDisconnect(c);
+
+ /* Fire free callback and clear all allocations. */
if (c->cbFree != NULL)
c->cbFree(c,c->privdataFree);
if (c->error != NULL)