]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Plug termination memory leaks
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Jan 2017 13:59:27 +0000 (13:59 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Jan 2017 13:59:27 +0000 (13:59 +0000)
src/controller.c
src/fuzzy_storage.c
src/hs_helper.c
src/libserver/cfg_utils.c
src/libserver/redis_pool.c
src/libstat/stat_config.c
src/log_helper.c
src/lua_worker.c
src/rspamd_proxy.c
src/worker.c

index 8949da73307d0cffe69c12814943a4b2f5372d04..73c63d483f8547d33ba5d72f23b4dbc0c2c8fb71 100644 (file)
@@ -3346,7 +3346,6 @@ start_controller_worker (struct rspamd_worker *worker)
        ctx->start_time = time (NULL);
        ctx->worker = worker;
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
        ctx->srv = worker->srv;
        ctx->custom_commands = g_hash_table_new (rspamd_strcase_hash,
                        rspamd_strcase_equal);
@@ -3529,9 +3528,9 @@ start_controller_worker (struct rspamd_worker *worker)
                munmap (m, ctx->cached_enable_password.len);
        }
 
-       REF_RELEASE (ctx->cfg);
        g_hash_table_unref (ctx->plugins);
        g_hash_table_unref (ctx->custom_commands);
+       REF_RELEASE (ctx->cfg);
 
        exit (EXIT_SUCCESS);
 }
index a1eb8099783e112c215f36eb12ed4ae96a887a44..62232f3759089f5e82696e392ca12f26e9f75b80 100644 (file)
@@ -2303,7 +2303,6 @@ start_fuzzy (struct rspamd_worker *worker)
        ctx->peer_fd = -1;
        ctx->worker = worker;
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
        double_to_tv (ctx->master_timeout, &ctx->master_io_tv);
 
        ctx->resolver = dns_resolver_init (worker->srv->logger,
index f4f3bed88018408f056a911a6a64ad58a73f2e9b..e3aee6cbcd6aea54e7e43c4ee2f6044c165b74a8 100644 (file)
@@ -268,7 +268,6 @@ start_hs_helper (struct rspamd_worker *worker)
        double tim;
 
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
 
        if (ctx->hs_dir == NULL) {
                ctx->hs_dir = ctx->cfg->hs_cache_dir;
index 606ef3cf79afe575d448994fbc9e4c25d322c9fc..b39503ee288ab99959576554ff8d7eb7e04a3932 100644 (file)
@@ -128,7 +128,8 @@ rspamd_config_new (void)
        cfg->classifiers_symbols = g_hash_table_new (rspamd_str_hash,
                        rspamd_str_equal);
        cfg->cfg_params = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
-       cfg->metrics_symbols = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
+       cfg->metrics_symbols = g_hash_table_new_full (rspamd_str_hash, rspamd_str_equal,
+                       NULL, (GDestroyNotify)g_list_free);
        cfg->debug_modules = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
        cfg->explicit_modules = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
        cfg->wrk_parsers = g_hash_table_new (g_int_hash, g_int_equal);
@@ -191,6 +192,29 @@ rspamd_config_free (struct rspamd_config *cfg)
        struct rspamd_config_post_load_script *sc, *sctmp;
 
        rspamd_map_remove_all (cfg);
+
+       DL_FOREACH_SAFE (cfg->finish_callbacks, sc, sctmp) {
+               luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
+               g_slice_free1 (sizeof (*sc), sc);
+       }
+
+       DL_FOREACH_SAFE (cfg->on_load, sc, sctmp) {
+               luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
+               g_slice_free1 (sizeof (*sc), sc);
+       }
+
+       if (cfg->monitored_ctx) {
+               rspamd_monitored_ctx_destroy (cfg->monitored_ctx);
+       }
+
+       g_list_free (cfg->classifiers);
+       g_list_free (cfg->metrics_list);
+       rspamd_symbols_cache_destroy (cfg->cache);
+#ifdef WITH_HIREDIS
+       if (cfg->redis_pool) {
+               rspamd_redis_pool_destroy (cfg->redis_pool);
+       }
+#endif
        ucl_object_unref (cfg->rcl_obj);
        ucl_object_unref (cfg->config_comments);
        ucl_object_unref (cfg->doc_strings);
@@ -213,28 +237,11 @@ rspamd_config_free (struct rspamd_config *cfg)
                g_free (cfg->checksum);
        }
 
-       DL_FOREACH_SAFE (cfg->finish_callbacks, sc, sctmp) {
-               luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
-               g_slice_free1 (sizeof (*sc), sc);
-       }
-
-       DL_FOREACH_SAFE (cfg->on_load, sc, sctmp) {
-               luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref);
-               g_slice_free1 (sizeof (*sc), sc);
-       }
-
-       if (cfg->monitored_ctx) {
-               rspamd_monitored_ctx_destroy (cfg->monitored_ctx);
-       }
-
-       g_list_free (cfg->classifiers);
-       g_list_free (cfg->metrics_list);
-       rspamd_symbols_cache_destroy (cfg->cache);
-       REF_RELEASE (cfg->libs_ctx);
        rspamd_re_cache_unref (cfg->re_cache);
        rspamd_upstreams_library_unref (cfg->ups_ctx);
        rspamd_mempool_delete (cfg->cfg_pool);
        lua_close (cfg->lua_state);
+       REF_RELEASE (cfg->libs_ctx);
        g_slice_free1 (sizeof (*cfg), cfg);
 }
 
@@ -1210,7 +1217,6 @@ rspamd_ucl_fin_cb (struct map_cb_data *data)
                data->prev_data;
        ucl_object_t *obj;
        struct ucl_parser *parser;
-       guint32 checksum;
        ucl_object_iter_t it = NULL;
        const ucl_object_t *cur;
        struct rspamd_config *cfg = data->map->cfg;
@@ -1227,7 +1233,6 @@ rspamd_ucl_fin_cb (struct map_cb_data *data)
                return;
        }
 
-       checksum = rspamd_cryptobox_fast_hash (cbdata->buf->str, cbdata->buf->len, 0);
        /* New data available */
        parser = ucl_parser_new (0);
        if (!ucl_parser_add_chunk (parser, cbdata->buf->str,
@@ -1398,9 +1403,6 @@ rspamd_config_new_metric_symbol (struct rspamd_config *cfg,
        if ((metric_list =
                        g_hash_table_lookup (cfg->metrics_symbols, sym_def->name)) == NULL) {
                metric_list = g_list_prepend (NULL, metric);
-               rspamd_mempool_add_destructor (cfg->cfg_pool,
-                               (rspamd_mempool_destruct_t)g_list_free,
-                               metric_list);
                g_hash_table_insert (cfg->metrics_symbols, sym_def->name, metric_list);
        }
        else {
index 2cf4b5961118cdcc5509c050291eb342c41cfc1d..cf64c3efe1f18ea15c433aba63e20891fc3bdc54 100644 (file)
@@ -112,7 +112,9 @@ rspamd_redis_pool_conn_dtor (struct rspamd_redis_pool_connection *conn)
                        }
                }
 
-               g_queue_unlink (conn->elt->active, conn->entry);
+               if (conn->entry) {
+                       g_queue_unlink (conn->elt->active, conn->entry);
+               }
        }
        else {
                msg_debug_rpool ("inactive connection removed");
@@ -132,7 +134,9 @@ rspamd_redis_pool_conn_dtor (struct rspamd_redis_pool_connection *conn)
                        redisAsyncFree (ac);
                }
 
-               g_queue_unlink (conn->elt->inactive, conn->entry);
+               if (conn->entry) {
+                       g_queue_unlink (conn->elt->inactive, conn->entry);
+               }
        }
 
 
@@ -149,11 +153,13 @@ rspamd_redis_pool_elt_dtor (gpointer p)
 
        for (cur = elt->active->head; cur != NULL; cur = g_list_next (cur)) {
                c = cur->data;
+               c->entry = NULL;
                REF_RELEASE (c);
        }
 
        for (cur = elt->inactive->head; cur != NULL; cur = g_list_next (cur)) {
                c = cur->data;
+               c->entry = NULL;
                REF_RELEASE (c);
        }
 
index 46e5dab31e424036d609175e25d70efcebb50312..b6b9000d57b11700b1b3725a15351771bb69c4f9 100644 (file)
@@ -161,7 +161,6 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base)
        stat_ctx->classifiers = g_ptr_array_new ();
        stat_ctx->async_elts = g_queue_new ();
        stat_ctx->ev_base = ev_base;
-       REF_RETAIN (stat_ctx->cfg);
 
        /* Create statfiles from the classifiers */
        cur = cfg->classifiers;
@@ -336,7 +335,6 @@ rspamd_stat_close (void)
        g_queue_free (stat_ctx->async_elts);
        g_ptr_array_free (st_ctx->statfiles, TRUE);
        g_ptr_array_free (st_ctx->classifiers, TRUE);
-       REF_RELEASE (stat_ctx->cfg);
        g_slice_free1 (sizeof (*st_ctx), st_ctx);
 
        /* Set global var to NULL */
index 5030c0fe5ae20c882e53746a99e809b847e59c1f..33a1a0ae55b9b07446c9055c8f3a3ab78515691f 100644 (file)
@@ -188,7 +188,6 @@ start_log_helper (struct rspamd_worker *worker)
                        NULL,
                        TRUE);
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
        ctx->scripts = worker->cf->scripts;
        ctx->L = ctx->cfg->lua_state;
        ctx->resolver = dns_resolver_init (worker->srv->logger,
index 296910761d3f1d287b04092a14f05f68ebdbfba7..624eb2082bb78b8febf34e39ea4ed834d4c79ced 100644 (file)
@@ -356,7 +356,6 @@ start_lua_worker (struct rspamd_worker *worker)
        L = worker->srv->cfg->lua_state;
        ctx->L = L;
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
 
        ctx->resolver = dns_resolver_init (worker->srv->logger,
                        ctx->ev_base,
index a6ca0b9727d90be10a0d92129865374a83726cf9..d4a2c1b57edc2636556f7e846694ce10cb683d89 100644 (file)
@@ -1465,7 +1465,6 @@ start_rspamd_proxy (struct rspamd_worker *worker)
        struct timeval rot_tv;
 
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
        ctx->ev_base = rspamd_prepare_worker (worker, "rspamd_proxy",
                        proxy_accept_socket,
                        TRUE);
index 7b0373c9e92664be2ef361d52bc6e6ab31277fe7..e7d71a99d175377de094de0d40e4da8e15ccd334 100644 (file)
@@ -82,6 +82,7 @@ rspamd_worker_finalize (gpointer user_data)
 
        msg_info_task ("finishing actions has been processed, terminating");
        event_base_loopexit (task->ev_base, &tv);
+       rspamd_session_destroy (task->s);
 
        return TRUE;
 }
@@ -111,6 +112,8 @@ rspamd_worker_call_finish_handlers (struct rspamd_worker *worker)
                }
 
                if (rspamd_session_pending (task->s)) {
+                       rspamd_session_destroy (task->s);
+
                        return TRUE;
                }
        }
@@ -599,7 +602,6 @@ start_worker (struct rspamd_worker *worker)
        struct rspamd_worker_log_pipe *lp, *ltmp;
 
        ctx->cfg = worker->srv->cfg;
-       REF_RETAIN (ctx->cfg);
        ctx->ev_base = rspamd_prepare_worker (worker, "normal", accept_socket, TRUE);
        msec_to_tv (ctx->timeout, &ctx->io_tv);
        rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base);