From 722a9675c2b2f929b14c047eae0b4b8b5213a06c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 5 May 2015 12:43:38 +0100 Subject: [PATCH] Remove memory leak in lua_redis. --- src/lua/lua_redis.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 3a1a8e89a..b224c3452 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -78,25 +78,30 @@ struct lua_redis_userdata { guint nargs; }; +static void +lua_redis_free_args (struct lua_redis_userdata *ud) +{ + guint i; + + if (ud->args) { + for (i = 0; i < ud->nargs; i ++) { + g_free (ud->args[i]); + } + + g_free (ud->args); + } +} static void lua_redis_fin (void *arg) { struct lua_redis_userdata *ud = arg; - guint i; if (ud->ctx) { redisAsyncFree (ud->ctx); + lua_redis_free_args (ud); event_del (&ud->timeout); luaL_unref (ud->L, LUA_REGISTRYINDEX, ud->cbref); - - if (ud->args) { - for (i = 0; i < ud->nargs; i ++) { - g_free (ud->args[i]); - } - - g_free (ud->args); - } } } @@ -211,7 +216,7 @@ lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv) } } else { - lua_redis_push_error ("received no data from server", ud, FALSE); + lua_redis_push_error ("received no data from server", ud, TRUE); } } else { @@ -350,6 +355,7 @@ lua_redis_make_request (lua_State *L) if (cbref != -1) { luaL_unref (L, LUA_REGISTRYINDEX, cbref); } + msg_err ("incorrect function invocation"); } } @@ -389,6 +395,7 @@ lua_redis_make_request (lua_State *L) if (ud->ctx == NULL || ud->ctx->err) { redisAsyncFree (ud->ctx); + lua_redis_free_args (ud); luaL_unref (ud->L, LUA_REGISTRYINDEX, ud->cbref); lua_pushboolean (L, FALSE); @@ -414,6 +421,7 @@ lua_redis_make_request (lua_State *L) } else { msg_info ("call to redis failed: %s", ud->ctx->errstr); + lua_redis_free_args (ud); redisAsyncFree (ud->ctx); luaL_unref (ud->L, LUA_REGISTRYINDEX, ud->cbref); } -- 2.39.5