]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix some minor code quality issue
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 12 Oct 2021 19:33:48 +0000 (20:33 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 12 Oct 2021 19:33:48 +0000 (20:33 +0100)
Found by: coverity scan

src/libstat/backends/mmaped_file.c
src/libstat/backends/redis_backend.c
src/libutil/sqlite_utils.c
src/lua/lua_common.c
src/plugins/fuzzy_check.c

index f87e9e6bd4db2b22202932eb1a0c788b665799aa..7d67fa053f930ce0ce9f1aec19e7781305eebd57 100644 (file)
@@ -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;
index 2fd69f43612c7342801858fc25660f3b8fb97db0..fdbb77f78f85a0da0af15de2f17f329d2aa0694c 100644 (file)
@@ -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;
        }
 
index 9bb0b9c1f2fcd6a2723c778ece6aa56d73db4ec9..2a9da5469bf5a17daaba9e86654760275f66736b 100644 (file)
@@ -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 ();
index cd557f816ef44854f7d8eafeaea85f0c5fbf4f54..ab411fa66bd61870e7a6f366ce97e37fa01c69c1 100644 (file)
@@ -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 */
index ea8bcf7567e4c317c42b2e7b3b94f6c3050e0af9..e26ce2a774b5cbbf425dbfb70cd59c79cee007f1 100644 (file)
@@ -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);