From e2e021a18220d7966cd7888db912e98108d717f7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 12 Oct 2021 20:33:48 +0100 Subject: [PATCH] [Minor] Fix some minor code quality issue Found by: coverity scan --- src/libstat/backends/mmaped_file.c | 1 + src/libstat/backends/redis_backend.c | 6 ++++-- src/libutil/sqlite_utils.c | 30 ++++++++++++++++++---------- src/lua/lua_common.c | 4 ++-- src/plugins/fuzzy_check.c | 1 + 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c index f87e9e6bd..7d67fa053 100644 --- a/src/libstat/backends/mmaped_file.c +++ b/src/libstat/backends/mmaped_file.c @@ -571,6 +571,7 @@ rspamd_mmaped_file_open (rspamd_mempool_t *pool, lock_fd = open (lock, O_WRONLY|O_CREAT|O_EXCL, 00600); if (lock_fd == -1) { + g_free (lock); msg_info_pool ("cannot open file %s, it is locked by another process", filename); return NULL; diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index 2fd69f436..fdbb77f78 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -153,15 +153,17 @@ rspamd_redis_expand_object (const gchar *pattern, gint err_idx; g_assert (ctx != NULL); + g_assert (task != NULL); stcf = ctx->stcf; L = task->cfg->lua_state; + g_assert (L != NULL); if (ctx->enable_users) { if (ctx->cbref_user == -1) { rcpt = rspamd_task_get_principal_recipient (task); } - else if (L) { + else { /* Execute lua function to get userdata */ lua_pushcfunction (L, &rspamd_lua_traceback); err_idx = lua_gettop (L); @@ -269,7 +271,7 @@ rspamd_redis_expand_object (const gchar *pattern, } - if (target == NULL || task == NULL) { + if (target == NULL) { return -1; } diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c index 9bb0b9c1f..2a9da5469 100644 --- a/src/libutil/sqlite_utils.c +++ b/src/libutil/sqlite_utils.c @@ -338,20 +338,28 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const rspamd_snprintf (lock_path, sizeof (lock_path), "%s.lock", path); lock_fd = open (lock_path, O_WRONLY|O_CREAT|O_EXCL, 00600); - if (lock_fd == -1 && (errno == EEXIST || errno == EBUSY)) { - msg_debug_pool_check ("checking %s to wait for db being initialized", lock_path); + if (lock_fd == -1) { + if (errno == EEXIST || errno == EBUSY) { + msg_debug_pool_check ("checking %s to wait for db being initialized", lock_path); - if (!rspamd_sqlite3_wait (pool, lock_path)) { - g_set_error (err, rspamd_sqlite3_quark (), - errno, "cannot create sqlite file %s: %s", - path, strerror (errno)); + if (!rspamd_sqlite3_wait(pool, lock_path)) { + g_set_error(err, rspamd_sqlite3_quark(), + errno, "cannot create sqlite file %s: %s", + path, strerror(errno)); - return NULL; - } + return NULL; + } - /* At this point we have database created */ - create = FALSE; - has_lock = FALSE; + + /* At this point we have database created */ + create = FALSE; + has_lock = FALSE; + } + else { + g_set_error(err, rspamd_sqlite3_quark(), + errno, "cannot lock sqlite file %s: %s", + path, strerror(errno)); + } } else { pid_t myself = getpid (); diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index cd557f816..ab411fa66 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1001,10 +1001,10 @@ rspamd_lua_init (bool wipe_mem) /* Set PRNG */ lua_getglobal (L, "math"); - lua_pushstring (L, "randomseed"); + lua_pushstring (L, "randomseed"); /* Push math.randomseed function on top of the stack */ lua_gettable (L, -2); lua_pushinteger (L, ottery_rand_uint64 ()); - lua_pcall (L, 1, 0, 0); + g_assert (lua_pcall (L, 1, 0, 0) == 0); lua_pop (L, 1); /* math table */ /* Modules state */ diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index ea8bcf756..e26ce2a77 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -3846,6 +3846,7 @@ static gint fuzzy_lua_unlearn_handler (lua_State *L) { struct rspamd_task *task = lua_check_task (L, 1); + g_assert (task != NULL); guint flag = 0, weight = 1.0, send_flags = 0; const gchar *symbol; struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context (task->cfg); -- 2.39.5