]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix memory leak in fuzzy storage khash tables
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 28 Oct 2025 15:51:51 +0000 (15:51 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 28 Oct 2025 15:51:51 +0000 (15:51 +0000)
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

index 05bd11fc3e2aca9d58d2977aa481b602c10fd0bd..0782dcb1e9ea1eb73c5506d4bf384316353ea6c7 100644 (file)
@@ -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,