From f616c2992a70926b9e3448562dff4addb3961985 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Mon, 22 Apr 2013 20:04:38 +0100 Subject: [PATCH] Free Redis context for custom connections GitHub issue #72 --- cmd.c | 6 ++++++ pool.c | 9 +++++++++ pool.h | 3 +++ 3 files changed, 18 insertions(+) diff --git a/cmd.c b/cmd.c index 18fca1e..7a86637 100644 --- a/cmd.c +++ b/cmd.c @@ -6,6 +6,7 @@ #include "worker.h" #include "http.h" #include "server.h" +#include "slog.h" #include "formats/json.h" #include "formats/raw.h" @@ -51,6 +52,11 @@ cmd_free(struct cmd *c) { free(c->if_none_match); if(c->mime_free) free(c->mime); + if (c->ac && /* we have a connection */ + (c->database != c->w->s->cfg->database /* custom DB */ + || cmd_is_subscribe(c))) { + pool_free_context(c->ac); + } free(c); } diff --git a/pool.c b/pool.c index 2670179..65ff84d 100644 --- a/pool.c +++ b/pool.c @@ -22,6 +22,15 @@ pool_new(struct worker *w, int count) { return p; } +void +pool_free_context(redisAsyncContext *ac) { + + if (ac) { + redisAsyncDisconnect(ac); + redisAsyncFree(ac); + } +} + static void pool_on_connect(const redisAsyncContext *ac, int status) { struct pool *p = ac->data; diff --git a/pool.h b/pool.h index cad236c..bd24ee9 100644 --- a/pool.h +++ b/pool.h @@ -21,6 +21,9 @@ struct pool { struct pool * pool_new(struct worker *w, int count); +void +pool_free_context(redisAsyncContext *ac); + redisAsyncContext * pool_connect(struct pool *p, int db_num, int attach);