diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-09-19 12:08:48 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-09-19 12:08:48 +0100 |
commit | 19424515ec8b3dcb133cef30bf10f8c6b19cc3aa (patch) | |
tree | f38a63933f8164f0a39a60cf04f628d5eef52fcb /src/lua/lua_task.c | |
parent | b5a184a0f8b376f3917f103b637a3db17925d2ae (diff) | |
download | rspamd-19424515ec8b3dcb133cef30bf10f8c6b19cc3aa.tar.gz rspamd-19424515ec8b3dcb133cef30bf10f8c6b19cc3aa.zip |
[Minor] Fix some leaks on error paths
Found by: coverity scan
Diffstat (limited to 'src/lua/lua_task.c')
-rw-r--r-- | src/lua/lua_task.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 393a370a8..589d45439 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -5059,22 +5059,28 @@ lua_task_get_symbols_tokens (lua_State *L) struct rspamd_task *task = lua_check_task (L, 1); struct tokens_foreach_cbdata cbd; - cbd.task = task; - cbd.L = L; - cbd.idx = 1; - cbd.normalize = TRUE; + if (task) { + cbd.task = task; + cbd.L = L; + cbd.idx = 1; + cbd.normalize = TRUE; - if (lua_type (L, 2) == LUA_TBOOLEAN) { - cbd.normalize = lua_toboolean (L, 2); + if (lua_type(L, 2) == LUA_TBOOLEAN) { + cbd.normalize = lua_toboolean(L, 2); + } + else { + cbd.normalize = TRUE; + } + + lua_createtable(L, + rspamd_symcache_stats_symbols_count(task->cfg->cache), 0); + rspamd_symcache_foreach(task->cfg->cache, tokens_foreach_cb, &cbd); } else { - cbd.normalize = TRUE; + return luaL_error (L, "invalid arguments"); } - lua_createtable (L, - rspamd_symcache_stats_symbols_count (task->cfg->cache), 0); - rspamd_symcache_foreach (task->cfg->cache, tokens_foreach_cb, &cbd); - + /* Return type is table created */ return 1; } @@ -6058,7 +6064,7 @@ lua_task_store_in_file (lua_State *L) gboolean force_new = FALSE, keep = FALSE; gchar fpath[PATH_MAX]; const gchar *tmpmask = NULL, *fname = NULL; - guint64 mode = 00600; + guint mode = 00600; gint fd; struct lua_file_cbdata *cbdata; GError *err = NULL; @@ -6097,7 +6103,7 @@ lua_task_store_in_file (lua_State *L) rspamd_snprintf (fpath, sizeof (fpath), "%s", tmpmask); } - fd = mkstemp (fpath); + fd = g_mkstemp_full (fpath, O_WRONLY|O_CREAT|O_EXCL, mode); fname = fpath; if (fd != -1) { |