diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-10 13:59:27 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-10 13:59:27 +0000 |
commit | 653ecce56f9215b189f9b0b556e79a6a7951e032 (patch) | |
tree | f3ba83cd151c128f6ac5cf17044aa31c8b30d915 /src | |
parent | 26a8dbfd045ae44a55dd3c690ac370806afa213f (diff) | |
download | rspamd-653ecce56f9215b189f9b0b556e79a6a7951e032.tar.gz rspamd-653ecce56f9215b189f9b0b556e79a6a7951e032.zip |
[Fix] Plug termination memory leaks
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 3 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 1 | ||||
-rw-r--r-- | src/hs_helper.c | 1 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 50 | ||||
-rw-r--r-- | src/libserver/redis_pool.c | 10 | ||||
-rw-r--r-- | src/libstat/stat_config.c | 2 | ||||
-rw-r--r-- | src/log_helper.c | 1 | ||||
-rw-r--r-- | src/lua_worker.c | 1 | ||||
-rw-r--r-- | src/rspamd_proxy.c | 1 | ||||
-rw-r--r-- | src/worker.c | 4 |
10 files changed, 38 insertions, 36 deletions
diff --git a/src/controller.c b/src/controller.c index 8949da733..73c63d483 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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); } diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index a1eb80997..62232f375 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -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, diff --git a/src/hs_helper.c b/src/hs_helper.c index f4f3bed88..e3aee6cbc 100644 --- a/src/hs_helper.c +++ b/src/hs_helper.c @@ -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; diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 606ef3cf7..b39503ee2 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -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 { diff --git a/src/libserver/redis_pool.c b/src/libserver/redis_pool.c index 2cf4b5961..cf64c3efe 100644 --- a/src/libserver/redis_pool.c +++ b/src/libserver/redis_pool.c @@ -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); } diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 46e5dab31..b6b9000d5 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -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 */ diff --git a/src/log_helper.c b/src/log_helper.c index 5030c0fe5..33a1a0ae5 100644 --- a/src/log_helper.c +++ b/src/log_helper.c @@ -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, diff --git a/src/lua_worker.c b/src/lua_worker.c index 296910761..624eb2082 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -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, diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index a6ca0b972..d4a2c1b57 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -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); diff --git a/src/worker.c b/src/worker.c index 7b0373c9e..e7d71a99d 100644 --- a/src/worker.c +++ b/src/worker.c @@ -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); |