diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-15 20:23:35 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-15 20:23:35 +0000 |
commit | 0e270dbe709e743ec840999c05e35f4d63be69b4 (patch) | |
tree | 810753d3258d55c35efc599f279d560accb6fe40 /src/lua/lua_redis.c | |
parent | e0446369d13269d07cecb5711fbab7d7bc64398a (diff) | |
download | rspamd-0e270dbe709e743ec840999c05e35f4d63be69b4.tar.gz rspamd-0e270dbe709e743ec840999c05e35f4d63be69b4.zip |
[Fix] Fix couple of issues
Found by: Coverity
Diffstat (limited to 'src/lua/lua_redis.c')
-rw-r--r-- | src/lua/lua_redis.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 2307db835..acb355faa 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -533,6 +533,7 @@ rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref) if (lua_istable (L, 1)) { /* Table version */ + lua_pushvalue (L, 1); lua_pushstring (L, "task"); lua_gettable (L, -2); if (lua_type (L, -1) == LUA_TUSERDATA) { @@ -621,6 +622,7 @@ rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref) dbname = lua_tostring (L, -1); } lua_pop (L, 1); + lua_pop (L, 1); /* table */ if (ret && addr != NULL) { @@ -817,6 +819,7 @@ lua_redis_make_request_sync (lua_State *L) redisReply *r; if (lua_istable (L, 1)) { + lua_pushvalue (L, 1); lua_pushstring (L, "cmd"); lua_gettable (L, -2); @@ -848,9 +851,13 @@ lua_redis_make_request_sync (lua_State *L) } lua_pop (L, 1); - lua_pushstring (L, "args"); - lua_gettable (L, -2); - lua_redis_parse_args (L, -1, cmd, &args, &arglens, &nargs); + if (cmd) { + lua_pushstring (L, "args"); + lua_gettable (L, -2); + lua_redis_parse_args (L, -1, cmd, &args, &arglens, &nargs); + lua_pop (L, 1); + } + lua_pop (L, 1); if (addr && cmd) { @@ -928,7 +935,6 @@ lua_redis_connect (lua_State *L) struct lua_redis_userdata *ud; struct lua_redis_ctx *ctx, **pctx; gdouble timeout = REDIS_DEFAULT_TIMEOUT; - gboolean ret = FALSE; ctx = rspamd_lua_redis_prepare_connection (L, NULL); @@ -936,10 +942,11 @@ lua_redis_connect (lua_State *L) ud = &ctx->d.async; lua_pushstring (L, "timeout"); - lua_gettable (L, -2); + lua_gettable (L, 1); if (lua_type (L, -1) == LUA_TNUMBER) { timeout = lua_tonumber (L, -1); } + lua_pop (L, 1); ud->timeout = timeout; } @@ -950,14 +957,9 @@ lua_redis_connect (lua_State *L) return 2; } - if (ret) { - pctx = lua_newuserdata (L, sizeof (ctx)); - *pctx = ctx; - rspamd_lua_setclass (L, "rspamd{redis}", -1); - } - else { - lua_pushnil (L); - } + pctx = lua_newuserdata (L, sizeof (ctx)); + *pctx = ctx; + rspamd_lua_setclass (L, "rspamd{redis}", -1); return 1; } |