]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] One more leak fix 5709/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 29 Oct 2025 12:34:57 +0000 (12:34 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 29 Oct 2025 12:34:57 +0000 (12:34 +0000)
src/fuzzy_storage.c

index 1f8cccef24d2a97bc1e793130e2f89c04f24dd39..656e13a45763c42c1ba52ad5d2692a6928dac766 100644 (file)
@@ -493,7 +493,8 @@ ucl_keymap_dtor_cb(struct map_cb_data *data)
                kh_foreach_value(jb->ctx->dynamic_keys, key, {
                        REF_RELEASE(key);
                });
-               kh_destroy(rspamd_fuzzy_keys_hash, jb->ctx->dynamic_keys);
+               /* Clear hash content but don't destroy - mempool destructor will handle it */
+               kh_clear(rspamd_fuzzy_keys_hash, jb->ctx->dynamic_keys);
 
                g_free(jb);
        }
@@ -812,6 +813,10 @@ fuzzy_key_dtor(gpointer p)
        struct fuzzy_key *key = p;
 
        if (key) {
+               if (key->key) {
+                       rspamd_keypair_unref(key->key);
+               }
+
                if (key->stat) {
                        REF_RELEASE(key->stat);
                }
@@ -3565,6 +3570,7 @@ fuzzy_add_keypair_from_ucl(struct rspamd_config *cfg, const ucl_object_t *obj,
        }
 
        if (rspamd_keypair_type(kp) != RSPAMD_KEYPAIR_KEX) {
+               rspamd_keypair_unref(kp);
                return FALSE;
        }
 
@@ -4308,6 +4314,9 @@ start_fuzzy(struct rspamd_worker *worker)
                struct fuzzy_keymap_ucl_buf *jb, **pjb;
 
                ctx->dynamic_keys = kh_init(rspamd_fuzzy_keys_hash);
+               rspamd_mempool_add_destructor(ctx->cfg->cfg_pool,
+                                                                         (rspamd_mempool_destruct_t) fuzzy_hash_table_dtor,
+                                                                         ctx->dynamic_keys);
                /* Now try to add map with ucl data */
                jb = g_malloc(sizeof(struct fuzzy_keymap_ucl_buf));
                pjb = g_malloc(sizeof(struct fuzzy_keymap_ucl_buf *));