From c693f721de9762ab0a82360e4c474f0d4b642007 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 28 Oct 2025 15:51:51 +0000 Subject: [PATCH] [Fix] Fix memory leak in fuzzy storage khash tables In init_fuzzy(), two khash tables were created but their destructors were not added to the config mempool: - ctx->default_forbidden_ids - ctx->weak_ids While these tables were destroyed in the worker cleanup code (before exit), this cleanup doesn't run during configtest, causing a memory leak. Fix: Add mempool destructors for both hash tables, similar to how ctx->keys and ctx->errors_ips are handled. This ensures proper cleanup in all scenarios including configtest. --- src/fuzzy_storage.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 05bd11fc3e..0782dcb1e9 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -3824,7 +3824,13 @@ init_fuzzy(struct rspamd_config *cfg) ctx->delay = NAN; ctx->tcp_timeout = DEFAULT_TCP_TIMEOUT; ctx->default_forbidden_ids = kh_init(fuzzy_key_ids_set); + rspamd_mempool_add_destructor(cfg->cfg_pool, + (rspamd_mempool_destruct_t) kh_destroy_fuzzy_key_ids_set, + ctx->default_forbidden_ids); ctx->weak_ids = kh_init(fuzzy_key_ids_set); + rspamd_mempool_add_destructor(cfg->cfg_pool, + (rspamd_mempool_destruct_t) kh_destroy_fuzzy_key_ids_set, + ctx->weak_ids); rspamd_rcl_register_worker_option(cfg, type, -- 2.47.3