]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Cleanup maps data on shutdown
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Jun 2018 10:47:36 +0000 (11:47 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 14 Jun 2018 14:15:19 +0000 (15:15 +0100)
13 files changed:
src/fuzzy_storage.c
src/libserver/cfg_utils.c
src/libserver/dynamic_cfg.c
src/libserver/worker_util.c
src/libutil/map.c
src/libutil/map.h
src/libutil/map_helpers.c
src/libutil/map_helpers.h
src/libutil/map_private.h
src/lua/lua_map.c
src/plugins/dkim_check.c
src/plugins/fuzzy_check.c
src/plugins/surbl.c

index 44b7c555e174a7a5373ed460bc5a9b5b549dcecc..2348220187b1a7c3026ba8dfe1d0b8cff4df72c5 100644 (file)
@@ -2880,7 +2880,10 @@ start_fuzzy (struct rspamd_worker *worker)
                struct rspamd_map *m;
 
                if ((m = rspamd_map_add_from_ucl (cfg, ctx->skip_map,
-                               "Skip hashes", rspamd_kv_list_read, rspamd_kv_list_fin,
+                               "Skip hashes",
+                               rspamd_kv_list_read,
+                               rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
                                (void **)&ctx->skip_hashes)) == NULL) {
                        msg_warn_config ("cannot load hashes list from %s",
                                        ucl_object_tostring (ctx->skip_map));
index e58232a007aaa4014a7e1dcf7aa8c1c31976ed83..ef5d89ff6c1e5d6f995b895db6cb93efe17b8569 100644 (file)
@@ -56,6 +56,7 @@ static gchar * rspamd_ucl_read_cb (gchar * chunk,
        struct map_cb_data *data,
        gboolean final);
 static void rspamd_ucl_fin_cb (struct map_cb_data *data);
+static void rspamd_ucl_dtor_cb (struct map_cb_data *data);
 
 guint rspamd_config_log_id = (guint)-1;
 RSPAMD_CONSTRUCTOR(rspamd_config_log_init)
@@ -1083,7 +1084,8 @@ rspamd_include_map_handler (const guchar *data, gsize len,
                           "ucl include",
                           rspamd_ucl_read_cb,
                           rspamd_ucl_fin_cb,
-                          (void **)pcbdata);
+                          rspamd_ucl_dtor_cb,
+                          (void **)pcbdata) != NULL;
 }
 
 /*
@@ -1364,6 +1366,19 @@ rspamd_ucl_fin_cb (struct map_cb_data *data)
        }
 }
 
+static void
+rspamd_ucl_dtor_cb (struct map_cb_data *data)
+{
+       struct rspamd_ucl_map_cbdata *cbdata = data->cur_data;
+
+       if (cbdata != NULL) {
+               if (cbdata->buf != NULL) {
+                       g_string_free (cbdata->buf, TRUE);
+               }
+               g_free (cbdata);
+       }
+}
+
 gboolean
 rspamd_check_module (struct rspamd_config *cfg, module_t *mod)
 {
@@ -1888,7 +1903,10 @@ rspamd_config_radix_from_ucl (struct rspamd_config *cfg,
 
                        if (rspamd_map_is_map (str)) {
                                if (rspamd_map_add_from_ucl (cfg, cur_elt,
-                                               description, rspamd_radix_read, rspamd_radix_fin,
+                                               description,
+                                               rspamd_radix_read,
+                                               rspamd_radix_fin,
+                                               rspamd_radix_dtor,
                                                (void **)target) == NULL) {
                                        g_set_error (err, g_quark_from_static_string ("rspamd-config"),
                                                        EINVAL, "bad map definition %s for %s", str,
@@ -1908,7 +1926,10 @@ rspamd_config_radix_from_ucl (struct rspamd_config *cfg,
                case UCL_OBJECT:
                        /* Should be a map description */
                        if (rspamd_map_add_from_ucl (cfg, cur_elt,
-                                       description, rspamd_radix_read, rspamd_radix_fin,
+                                       description,
+                                       rspamd_radix_read,
+                                       rspamd_radix_fin,
+                                       rspamd_radix_dtor,
                                        (void **)target) == NULL) {
                                g_set_error (err, g_quark_from_static_string ("rspamd-config"),
                                                EINVAL, "bad map object for %s", ucl_object_key (obj));
index 584590ed978c4ebb650617f1bf306736379e9b6b..17818888e5ae24d6141e11cc8e14d9056fb88bae 100644 (file)
@@ -222,6 +222,22 @@ json_config_fin_cb (struct map_cb_data *data)
        jb->cfg->current_dynamic_conf = top;
 }
 
+static void
+json_config_dtor_cb (struct map_cb_data *data)
+{
+       struct config_json_buf *jb;
+
+       if (data->cur_data) {
+               jb = data->cur_data;
+               /* Clean prev data */
+               if (jb->buf) {
+                       g_string_free (jb->buf, TRUE);
+               }
+
+               g_free (jb);
+       }
+}
+
 /**
  * Init dynamic configuration using map logic and specific configuration
  * @param cfg config file
@@ -244,8 +260,13 @@ init_dynamic_config (struct rspamd_config *cfg)
        *pjb = jb;
        cfg->current_dynamic_conf = ucl_object_typed_new (UCL_ARRAY);
 
-       if (!rspamd_map_add (cfg, cfg->dynamic_conf, "Dynamic configuration map",
-               json_config_read_cb, json_config_fin_cb, (void **)pjb)) {
+       if (!rspamd_map_add (cfg,
+                       cfg->dynamic_conf,
+                       "Dynamic configuration map",
+                       json_config_read_cb,
+                       json_config_fin_cb,
+                       json_config_dtor_cb,
+                       (void **)pjb)) {
                msg_err ("cannot add map for configuration %s", cfg->dynamic_conf);
        }
 }
index 8c4e934bc9367673f51910dd15f5fdc2d33a570b..c60273dea2882915d67ec5d98fdadc4ae9d0bbd6 100644 (file)
@@ -342,7 +342,6 @@ rspamd_worker_stop_accept (struct rspamd_worker *worker)
 {
        GList *cur;
        struct event *events;
-       struct rspamd_map *map;
 
        /* Remove all events */
        cur = worker->accept_events;
@@ -383,15 +382,7 @@ rspamd_worker_stop_accept (struct rspamd_worker *worker)
 #endif
 
        /* Cleanup maps */
-       for (cur = worker->srv->cfg->maps; cur != NULL; cur = g_list_next (cur)) {
-               map = cur->data;
-
-               if (map->dtor) {
-                       map->dtor (map->dtor_data);
-               }
-
-               map->dtor = NULL;
-       }
+       rspamd_map_remove_all (worker->srv->cfg);
 }
 
 static rspamd_fstring_t *
index f666ad98d90535f1df4b211b4b922d9b0a67b0f6..efbf85c45364a2b10a0de792467f14bc1bf37d5f 100644 (file)
@@ -47,15 +47,6 @@ static void rspamd_map_periodic_callback (gint fd, short what, void *ud);
 static void rspamd_map_schedule_periodic (struct rspamd_map *map, gboolean locked,
                gboolean initial, gboolean errored);
 
-struct rspamd_http_map_cached_cbdata {
-       struct event timeout;
-       struct rspamd_storage_shmem *shm;
-       struct rspamd_map *map;
-       struct http_map_data *data;
-       guint64 gen;
-       time_t last_checked;
-};
-
 guint rspamd_map_log_id = (guint)-1;
 RSPAMD_CONSTRUCTOR(rspamd_map_log_init)
 {
@@ -285,8 +276,8 @@ free_http_cbdata_common (struct http_callback_data *cbd, gboolean plan_new)
 static void
 free_http_cbdata (struct http_callback_data *cbd)
 {
-       cbd->map->dtor = NULL;
-       cbd->map->dtor_data = NULL;
+       cbd->map->tmp_dtor = NULL;
+       cbd->map->tmp_dtor_data = NULL;
 
        free_http_cbdata_common (cbd, TRUE);
 }
@@ -365,6 +356,7 @@ rspamd_map_cache_cb (gint fd, short what, gpointer ud)
                event_add (&cache_cbd->timeout, &tv);
        }
        else {
+               map->cur_cache_cbd = NULL;
                g_atomic_int_set (&map->cache->available, 0);
                MAP_RELEASE (cache_cbd->shm, "rspamd_http_map_cached_cbdata");
                msg_info_map ("cached data is now expired for %s", map->name);
@@ -453,6 +445,7 @@ http_map_finish (struct rspamd_http_connection *conn,
                        cbd->periodic->cur_backend = 0;
                        /* Reset cache, old cached data will be cleaned on timeout */
                        g_atomic_int_set (&map->cache->available, 0);
+                       map->cur_cache_cbd = NULL;
 
                        rspamd_map_periodic_callback (-1, EV_TIMEOUT, cbd->periodic);
                        MAP_RELEASE (cbd, "http_callback_data");
@@ -677,6 +670,7 @@ read_data:
                                cache_cbd);
                event_base_set (cbd->ev_base, &cache_cbd->timeout);
                event_add (&cache_cbd->timeout, &tv);
+               map->cur_cache_cbd = cache_cbd;
 
                if (map->next_check) {
                        rspamd_http_date_format (next_check_date, sizeof (next_check_date),
@@ -1396,8 +1390,8 @@ check:
                        MAP_RETAIN (cbd, "http_callback_data");
                }
 
-               map->dtor = free_http_cbdata_dtor;
-               map->dtor_data = cbd;
+               map->tmp_dtor = free_http_cbdata_dtor;
+               map->tmp_dtor_data = cbd;
        }
        else {
                msg_warn_map ("cannot load map: DNS resolver is not initialized");
@@ -1663,6 +1657,7 @@ rspamd_map_remove_all (struct rspamd_config *cfg)
        struct rspamd_map *map;
        GList *cur;
        struct rspamd_map_backend *bk;
+       struct map_cb_data cbdata;
        guint i;
 
        for (cur = cfg->maps; cur != NULL; cur = g_list_next (cur)) {
@@ -1674,11 +1669,27 @@ rspamd_map_remove_all (struct rspamd_config *cfg)
                }
 
                if (g_atomic_int_compare_and_exchange (&map->cache->available, 1, 0)) {
+                       if (map->cur_cache_cbd) {
+                               MAP_RELEASE (map->cur_cache_cbd->shm, "rspamd_http_map_cached_cbdata");
+                               event_del (&map->cur_cache_cbd->timeout);
+                               g_free (map->cur_cache_cbd);
+                               map->cur_cache_cbd = NULL;
+                       }
+
                        unlink (map->cache->shmem_name);
                }
 
+               if (map->tmp_dtor) {
+                       map->tmp_dtor (map->tmp_dtor_data);
+               }
+
                if (map->dtor) {
-                       map->dtor (map->dtor_data);
+                       cbdata.prev_data = NULL;
+                       cbdata.map = map;
+                       cbdata.cur_data = *map->user_data;
+
+                       map->dtor (&cbdata);
+                       *map->user_data = NULL;
                }
        }
 
@@ -2015,11 +2026,12 @@ rspamd_map_add_static_string (struct rspamd_config *cfg,
 
 struct rspamd_map *
 rspamd_map_add (struct rspamd_config *cfg,
-       const gchar *map_line,
-       const gchar *description,
-       map_cb_t read_callback,
-       map_fin_cb_t fin_callback,
-       void **user_data)
+                               const gchar *map_line,
+                               const gchar *description,
+                               map_cb_t read_callback,
+                               map_fin_cb_t fin_callback,
+                               map_dtor_t dtor,
+                               void **user_data)
 {
        struct rspamd_map *map;
        struct rspamd_map_backend *bk;
@@ -2032,6 +2044,7 @@ rspamd_map_add (struct rspamd_config *cfg,
        map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_map));
        map->read_callback = read_callback;
        map->fin_callback = fin_callback;
+       map->dtor = dtor;
        map->user_data = user_data;
        map->cfg = cfg;
        map->id = rspamd_random_uint64_fast ();
@@ -2065,11 +2078,12 @@ rspamd_map_add (struct rspamd_config *cfg,
 
 struct rspamd_map*
 rspamd_map_add_from_ucl (struct rspamd_config *cfg,
-       const ucl_object_t *obj,
-       const gchar *description,
-       map_cb_t read_callback,
-       map_fin_cb_t fin_callback,
-       void **user_data)
+                                                const ucl_object_t *obj,
+                                                const gchar *description,
+                                                map_cb_t read_callback,
+                                                map_fin_cb_t fin_callback,
+                                                map_dtor_t dtor,
+                                                void **user_data)
 {
        ucl_object_iter_t it = NULL;
        const ucl_object_t *cur, *elt;
@@ -2082,12 +2096,13 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
        if (ucl_object_type (obj) == UCL_STRING) {
                /* Just a plain string */
                return rspamd_map_add (cfg, ucl_object_tostring (obj), description,
-                               read_callback, fin_callback, user_data);
+                               read_callback, fin_callback, dtor, user_data);
        }
 
        map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_map));
        map->read_callback = read_callback;
        map->fin_callback = fin_callback;
+       map->dtor = dtor;
        map->user_data = user_data;
        map->cfg = cfg;
        map->id = rspamd_random_uint64_fast ();
index d10ee331a5acaa95e38fea3ceb6ad8add030fee4..e12df4369d1c73f706297942dc55d0dba4ea1e44 100644 (file)
@@ -22,6 +22,7 @@ struct map_cb_data;
 typedef gchar * (*map_cb_t)(gchar *chunk, gint len,
        struct map_cb_data *data, gboolean final);
 typedef void (*map_fin_cb_t)(struct map_cb_data *data);
+typedef void (*map_dtor_t)(struct map_cb_data *data);
 
 typedef gboolean (*rspamd_map_traverse_cb)(gconstpointer key,
                gconstpointer value, gsize hits, gpointer ud);
@@ -56,21 +57,23 @@ gboolean rspamd_map_is_map (const gchar *map_line);
  * Add map from line
  */
 struct rspamd_map* rspamd_map_add (struct rspamd_config *cfg,
-       const gchar *map_line,
-       const gchar *description,
-       map_cb_t read_callback,
-       map_fin_cb_t fin_callback,
-       void **user_data);
+                                                                  const gchar *map_line,
+                                                                  const gchar *description,
+                                                                  map_cb_t read_callback,
+                                                                  map_fin_cb_t fin_callback,
+                                                                  map_dtor_t dtor,
+                                                                  void **user_data);
 
 /**
  * Add map from ucl
  */
 struct rspamd_map* rspamd_map_add_from_ucl (struct rspamd_config *cfg,
-       const ucl_object_t *obj,
-       const gchar *description,
-       map_cb_t read_callback,
-       map_fin_cb_t fin_callback,
-       void **user_data);
+                                                                                       const ucl_object_t *obj,
+                                                                                       const gchar *description,
+                                                                                       map_cb_t read_callback,
+                                                                                       map_fin_cb_t fin_callback,
+                                                                                       map_dtor_t dtor,
+                                                                                       void **user_data);
 
 /**
  * Start watching of maps by adding events to libevent event loop
index d0e3e2e95dcd832f08c619c298b328cb5f74288c..6c8117cff32aafd5a6328cf4a166ed2cfcd76fc2 100644 (file)
@@ -813,6 +813,17 @@ rspamd_kv_list_fin (struct map_cb_data *data)
        }
 }
 
+void
+rspamd_kv_list_dtor (struct map_cb_data *data)
+{
+       struct rspamd_hash_map_helper *htb;
+
+       if (data->cur_data) {
+               htb = (struct rspamd_hash_map_helper *)data->cur_data;
+               rspamd_map_helper_destroy_hash (htb);
+       }
+}
+
 gchar *
 rspamd_radix_read (
                gchar * chunk,
@@ -858,6 +869,17 @@ rspamd_radix_fin (struct map_cb_data *data)
        }
 }
 
+void
+rspamd_radix_dtor (struct map_cb_data *data)
+{
+       struct rspamd_radix_map_helper *r;
+
+       if (data->cur_data) {
+               r = (struct rspamd_radix_map_helper *)data->cur_data;
+               rspamd_map_helper_destroy_radix (r);
+       }
+}
+
 static void
 rspamd_re_map_finalize (struct rspamd_regexp_map_helper *re_map)
 {
@@ -1037,6 +1059,13 @@ rspamd_regexp_list_fin (struct map_cb_data *data)
                data->map->digest = rspamd_cryptobox_fast_hash_final (&re_map->hst);
        }
 }
+void
+rspamd_regexp_list_dtor (struct map_cb_data *data)
+{
+       if (data->cur_data) {
+               rspamd_map_helper_destroy_regexp (data->cur_data);
+       }
+}
 
 #ifdef WITH_HYPERSCAN
 static int
index bd933fbf293a33daaef7cf208bb148f9f01c17b9..28a5e336bbc9a70ccedff8803f39ba4797795138 100644 (file)
@@ -53,7 +53,7 @@ gchar * rspamd_radix_read (
                struct map_cb_data *data,
                gboolean final);
 void rspamd_radix_fin (struct map_cb_data *data);
-
+void rspamd_radix_dtor (struct map_cb_data *data);
 
 /**
  * Kv list is an ordinal list of keys and values separated by whitespace
@@ -64,6 +64,7 @@ gchar * rspamd_kv_list_read (
                struct map_cb_data *data,
                gboolean final);
 void rspamd_kv_list_fin (struct map_cb_data *data);
+void rspamd_kv_list_dtor (struct map_cb_data *data);
 
 /**
  * Regexp list is a list of regular expressions
@@ -85,6 +86,7 @@ gchar * rspamd_glob_list_read_single (
                struct map_cb_data *data,
                gboolean final);
 void rspamd_regexp_list_fin (struct map_cb_data *data);
+void rspamd_regexp_list_dtor (struct map_cb_data *data);
 
 /**
  * FSM for lists parsing (support comments, blank lines and partial replies)
index 1ea8d804070bd0a111b4880917f7eaca33dacb60..b8543356bdedf2c00209048cd0d72853197f085f 100644 (file)
@@ -23,7 +23,7 @@
 #include "map.h"
 #include "ref.h"
 
-typedef void (*rspamd_map_dtor) (gpointer p);
+typedef void (*rspamd_map_tmp_dtor) (gpointer p);
 extern guint rspamd_map_log_id;
 #define msg_err_map(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
                "map", map->tag, \
@@ -95,6 +95,15 @@ struct rspamd_map_backend {
        ref_entry_t ref;
 };
 
+struct rspamd_http_map_cached_cbdata {
+       struct event timeout;
+       struct rspamd_storage_shmem *shm;
+       struct rspamd_map *map;
+       struct http_map_data *data;
+       guint64 gen;
+       time_t last_checked;
+};
+
 struct rspamd_map_cachepoint {
        gint available;
        gsize len;
@@ -108,14 +117,15 @@ struct rspamd_map {
        GPtrArray *backends;
        map_cb_t read_callback;
        map_fin_cb_t fin_callback;
+       map_dtor_t dtor;
        void **user_data;
        struct event_base *ev_base;
        gchar *description;
        gchar *name;
        guint32 id;
        gboolean scheduled_check;
-       rspamd_map_dtor dtor;
-       gpointer dtor_data;
+       rspamd_map_tmp_dtor tmp_dtor;
+       gpointer tmp_dtor_data;
        rspamd_map_traverse_function traverse_function;
        gpointer lua_map;
        gsize nelts;
@@ -129,6 +139,8 @@ struct rspamd_map {
        gint *locked;
        /* Shared cache data */
        struct rspamd_map_cachepoint *cache;
+       /* Non-shared for cache owner, used to cleanup cache */
+       struct rspamd_http_map_cached_cbdata *cur_cache_cbd;
        gchar tag[MEMPOOL_UID_LEN];
 };
 
index 2d2a098d244ae5f3592606ee511fbded858f79b8..d5914706ce751b0ea86b867f9c1c51cff5b759f7 100644 (file)
@@ -156,6 +156,7 @@ lua_config_add_radix_map (lua_State *L)
                if ((m = rspamd_map_add (cfg, map_line, description,
                                rspamd_radix_read,
                                rspamd_radix_fin,
+                               rspamd_radix_dtor,
                                (void **)&map->data.radix)) == NULL) {
                        msg_warn_config ("invalid radix map %s", map_line);
                        lua_pushnil (L);
@@ -211,6 +212,7 @@ lua_config_radix_from_config (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, fake_obj, "static radix map",
                                        rspamd_radix_read,
                                        rspamd_radix_fin,
+                                       rspamd_radix_dtor,
                                        (void **)&map->data.radix)) == NULL) {
                                msg_err_config ("invalid radix map static");
                                lua_pushnil (L);
@@ -270,6 +272,7 @@ lua_config_radix_from_ucl (lua_State *L)
                if ((m = rspamd_map_add_from_ucl (cfg, fake_obj, "static radix map",
                                rspamd_radix_read,
                                rspamd_radix_fin,
+                               rspamd_radix_dtor,
                                (void **)&map->data.radix)) == NULL) {
                        msg_err_config ("invalid radix map static");
                        lua_pushnil (L);
@@ -311,6 +314,7 @@ lua_config_add_hash_map (lua_State *L)
                if ((m = rspamd_map_add (cfg, map_line, description,
                                rspamd_kv_list_read,
                                rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
                                (void **)&map->data.hash)) == NULL) {
                        msg_warn_config ("invalid set map %s", map_line);
                        lua_pushnil (L);
@@ -349,6 +353,7 @@ lua_config_add_kv_map (lua_State *L)
                if ((m = rspamd_map_add (cfg, map_line, description,
                                rspamd_kv_list_read,
                                rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
                                (void **)&map->data.hash)) == NULL) {
                        msg_warn_config ("invalid hash map %s", map_line);
                        lua_pushnil (L);
@@ -441,6 +446,23 @@ lua_map_fin (struct map_cb_data *data)
        cbdata->data = rspamd_fstring_assign (cbdata->data, "", 0);
 }
 
+static void
+lua_map_dtor (struct map_cb_data *data)
+{
+       struct lua_map_callback_data *cbdata;
+
+       if (data->cur_data) {
+               cbdata = (struct lua_map_callback_data *)data->cur_data;
+               if (cbdata->ref != -1) {
+                       luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->ref);
+               }
+
+               if (cbdata->data) {
+                       rspamd_fstring_free (cbdata->data);
+               }
+       }
+}
+
 gint
 lua_config_add_map (lua_State *L)
 {
@@ -488,7 +510,9 @@ lua_config_add_map (lua_State *L)
                        cbdata->ref = cbidx;
 
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
-                                       lua_map_read, lua_map_fin,
+                                       lua_map_read,
+                                       lua_map_fin,
+                                       lua_map_dtor,
                                        (void **)&map->data.cbdata)) == NULL) {
 
                                if (cbidx != -1) {
@@ -513,6 +537,7 @@ lua_config_add_map (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_kv_list_read,
                                        rspamd_kv_list_fin,
+                                       rspamd_kv_list_dtor,
                                        (void **)&map->data.hash)) == NULL) {
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
@@ -529,6 +554,7 @@ lua_config_add_map (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_kv_list_read,
                                        rspamd_kv_list_fin,
+                                       rspamd_kv_list_dtor,
                                        (void **)&map->data.hash)) == NULL) {
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
@@ -545,6 +571,7 @@ lua_config_add_map (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_radix_read,
                                        rspamd_radix_fin,
+                                       rspamd_radix_dtor,
                                        (void **)&map->data.radix)) == NULL) {
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
@@ -561,6 +588,7 @@ lua_config_add_map (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_regexp_list_read_single,
                                        rspamd_regexp_list_fin,
+                                       rspamd_regexp_list_dtor,
                                        (void **) &map->data.re_map)) == NULL) {
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
@@ -577,6 +605,7 @@ lua_config_add_map (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_regexp_list_read_multiple,
                                        rspamd_regexp_list_fin,
+                                       rspamd_regexp_list_dtor,
                                        (void **) &map->data.re_map)) == NULL) {
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
@@ -593,6 +622,7 @@ lua_config_add_map (lua_State *L)
                        if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
                                        rspamd_glob_list_read_single,
                                        rspamd_regexp_list_fin,
+                                       rspamd_regexp_list_dtor,
                                        (void **) &map->data.re_map)) == NULL) {
                                lua_pushnil (L);
                                ucl_object_unref (map_obj);
index 74bc4ea546fac1014799c61f1cde5a7141b2fd7f..ba2d9e2e327cd25dfa5fe62094ed8581b54c5605 100644 (file)
@@ -409,8 +409,11 @@ dkim_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "dkim", "domains")) != NULL) {
                if (!rspamd_map_add_from_ucl (cfg, value,
-                       "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin,
-                       (void **)&dkim_module_ctx->dkim_domains)) {
+                               "DKIM domains",
+                               rspamd_kv_list_read,
+                               rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
+                               (void **)&dkim_module_ctx->dkim_domains)) {
                        msg_warn_config ("cannot load dkim domains list from %s",
                                ucl_object_tostring (value));
                }
@@ -425,7 +428,10 @@ dkim_module_config (struct rspamd_config *cfg)
        if (!got_trusted && (value =
                        rspamd_config_get_module_opt (cfg, "dkim", "trusted_domains")) != NULL) {
                if (!rspamd_map_add_from_ucl (cfg, value,
-                               "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin,
+                               "DKIM domains",
+                               rspamd_kv_list_read,
+                               rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
                                (void **)&dkim_module_ctx->dkim_domains)) {
                        msg_warn_config ("cannot load dkim domains list from %s",
                                        ucl_object_tostring (value));
index c4318777f1b7c61a9ef3618a8c1860167a31ad6d..0266d3eddbc2c975b09676e55cfde7cab3ec5d69 100644 (file)
@@ -425,8 +425,11 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj,
 
        if ((value = ucl_object_lookup (obj, "skip_hashes")) != NULL) {
                rspamd_map_add_from_ucl (cfg, value,
-                       "Fuzzy hashes whitelist", rspamd_kv_list_read, rspamd_kv_list_fin,
-                       (void **)&rule->skip_map);
+                               "Fuzzy hashes whitelist",
+                               rspamd_kv_list_read,
+                               rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
+                               (void **)&rule->skip_map);
                rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool,
                                (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_radix,
                                rule->skip_map);
index d0bdd3b8cf2fe2cd15d90e411ba34ffe3650a807..238f14fb204bef82e02610d2ef6049410db308b5 100644 (file)
@@ -269,6 +269,23 @@ fin_exceptions_list (struct map_cb_data *data)
        }
 }
 
+static void
+dtor_exceptions_list (struct map_cb_data *data)
+{
+       GHashTable **t;
+       gint i;
+
+       if (data->cur_data) {
+               t = data->cur_data;
+               for (i = 0; i < MAX_LEVELS; i++) {
+                       if (t[i] != NULL) {
+                               g_hash_table_destroy (t[i]);
+                       }
+                       t[i] = NULL;
+               }
+       }
+}
+
 static void
 redirector_insert (gpointer st, gconstpointer key, gconstpointer value)
 {
@@ -361,6 +378,18 @@ fin_redirectors_list (struct map_cb_data *data)
        surbl_module_ctx->redirector_tlds = tld_hash;
 }
 
+void
+dtor_redirectors_list (struct map_cb_data *data)
+{
+       GHashTable *tld_hash;
+
+       if (data->cur_data) {
+               tld_hash = data->cur_data;
+
+               g_hash_table_unref (tld_hash);
+       }
+}
+
 gint
 surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 {
@@ -946,8 +975,11 @@ surbl_module_config (struct rspamd_config *cfg)
                rspamd_config_get_module_opt (cfg, "surbl",
                "redirector_hosts_map")) != NULL) {
                if (!rspamd_map_add_from_ucl (cfg, value,
-                       "SURBL redirectors list", read_redirectors_list, fin_redirectors_list,
-                       (void **)&surbl_module_ctx->redirector_map_data)) {
+                               "SURBL redirectors list",
+                               read_redirectors_list,
+                               fin_redirectors_list,
+                               dtor_redirectors_list,
+                               (void **)&surbl_module_ctx->redirector_map_data)) {
 
                        msg_warn_config ("bad redirectors map definition: %s",
                                        ucl_obj_tostring (value));
@@ -958,13 +990,18 @@ surbl_module_config (struct rspamd_config *cfg)
                rspamd_config_get_module_opt (cfg, "surbl", "exceptions")) != NULL) {
                rspamd_map_add_from_ucl (cfg, value,
                                "SURBL exceptions list",
-                               read_exceptions_list, fin_exceptions_list,
+                               read_exceptions_list,
+                               fin_exceptions_list,
+                               dtor_exceptions_list,
                                (void **)&surbl_module_ctx->exceptions);
        }
        if ((value =
                        rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
                rspamd_map_add_from_ucl (cfg, value,
-                               "SURBL whitelist", rspamd_kv_list_read, rspamd_kv_list_fin,
+                               "SURBL whitelist",
+                               rspamd_kv_list_read,
+                               rspamd_kv_list_fin,
+                               rspamd_kv_list_dtor,
                                (void **)&surbl_module_ctx->whitelist);
        }