]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Eliminate all specific C plugins pools
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Jul 2018 10:14:30 +0000 (11:14 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Jul 2018 10:14:30 +0000 (11:14 +0100)
src/plugins/chartable.c
src/plugins/dkim_check.c
src/plugins/spf.c
src/plugins/surbl.c

index 0d409480a77bdf5c50db0a882a1b42ac56cceedf..c9df2269a340033182407283084536cf6d17c7ae 100644 (file)
@@ -88,8 +88,6 @@ chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 {
        if (chartable_module_ctx == NULL) {
                chartable_module_ctx = g_malloc (sizeof (struct chartable_ctx));
-
-               chartable_module_ctx->chartable_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
                chartable_module_ctx->max_word_len = 10;
        }
 
@@ -164,9 +162,6 @@ chartable_module_config (struct rspamd_config *cfg)
 gint
 chartable_module_reconfig (struct rspamd_config *cfg)
 {
-       rspamd_mempool_delete (chartable_module_ctx->chartable_pool);
-       chartable_module_ctx->chartable_pool = rspamd_mempool_new (1024, NULL);
-
        return chartable_module_config (cfg);
 }
 
index 2ab2267370d840da701e3fc490dc27389e3e60bc..299382e723ef4669e65e554fcbd3b4d1cb569e0b 100644 (file)
@@ -128,7 +128,6 @@ dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
        if (dkim_module_ctx == NULL) {
                dkim_module_ctx = g_malloc0 (sizeof (struct dkim_ctx));
 
-               dkim_module_ctx->dkim_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "dkim");
                dkim_module_ctx->sign_headers = default_sign_headers;
                dkim_module_ctx->sign_condition_ref = -1;
                dkim_module_ctx->max_sigs = DEFAULT_MAX_SIGS;
@@ -401,10 +400,6 @@ dkim_module_config (struct rspamd_config *cfg)
 
                rspamd_config_radix_from_ucl (cfg, value, "DKIM whitelist",
                                &dkim_module_ctx->whitelist_ip, NULL);
-               rspamd_mempool_add_destructor (dkim_module_ctx->dkim_pool,
-                               (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_radix,
-                               dkim_module_ctx->whitelist_ip);
-
        }
 
        if ((value =
@@ -419,9 +414,6 @@ dkim_module_config (struct rspamd_config *cfg)
                                ucl_object_tostring (value));
                }
                else {
-                       rspamd_mempool_add_destructor (dkim_module_ctx->dkim_pool,
-                                       (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_hash,
-                                       dkim_module_ctx->dkim_domains);
                        got_trusted = TRUE;
                }
        }
@@ -438,9 +430,6 @@ dkim_module_config (struct rspamd_config *cfg)
                                        ucl_object_tostring (value));
                }
                else {
-                       rspamd_mempool_add_destructor (dkim_module_ctx->dkim_pool,
-                                       (rspamd_mempool_destruct_t)rspamd_map_helper_destroy_hash,
-                                       dkim_module_ctx->dkim_domains);
                        got_trusted = TRUE;
                }
        }
@@ -540,7 +529,7 @@ dkim_module_config (struct rspamd_config *cfg)
                                        dkim_module_ctx->sign_condition_ref = luaL_ref (cfg->lua_state,
                                                        LUA_REGISTRYINDEX);
                                        rspamd_lua_add_ref_dtor (cfg->lua_state,
-                                                       dkim_module_ctx->dkim_pool,
+                                                       cfg->cfg_pool,
                                                        dkim_module_ctx->sign_condition_ref);
 
                                        rspamd_symbols_cache_add_symbol (cfg->cache,
@@ -865,7 +854,6 @@ dkim_module_reconfig (struct rspamd_config *cfg)
        struct module_ctx saved_ctx;
 
        saved_ctx = dkim_module_ctx->ctx;
-       rspamd_mempool_delete (dkim_module_ctx->dkim_pool);
 
        if (dkim_module_ctx->dkim_hash) {
                rspamd_lru_hash_destroy (dkim_module_ctx->dkim_hash);
@@ -877,7 +865,6 @@ dkim_module_reconfig (struct rspamd_config *cfg)
 
        memset (dkim_module_ctx, 0, sizeof (*dkim_module_ctx));
        dkim_module_ctx->ctx = saved_ctx;
-       dkim_module_ctx->dkim_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "dkim");
        dkim_module_ctx->sign_headers = default_sign_headers;
        dkim_module_ctx->sign_condition_ref = -1;
        dkim_module_ctx->max_sigs = DEFAULT_MAX_SIGS;
index 1c8ec1fa9bf0a2d56fd851ba91f951ee66387e2f..5bdf044888c8b35cd25d23f2ba7f0a5ec1512b8f 100644 (file)
@@ -55,7 +55,6 @@ struct spf_ctx {
        const gchar *symbol_na;
        const gchar *symbol_permfail;
 
-       rspamd_mempool_t *spf_pool;
        struct rspamd_radix_map_helper *whitelist_ip;
        rspamd_lru_hash_t *spf_hash;
 
@@ -85,9 +84,7 @@ gint
 spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 {
        if (spf_module_ctx == NULL) {
-               spf_module_ctx = g_malloc (sizeof (struct spf_ctx));
-
-               spf_module_ctx->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+               spf_module_ctx = g_malloc0 (sizeof (struct spf_ctx));
        }
 
        *ctx = (struct module_ctx *)spf_module_ctx;
@@ -332,13 +329,10 @@ spf_module_reconfig (struct rspamd_config *cfg)
        struct module_ctx saved_ctx;
 
        saved_ctx = spf_module_ctx->ctx;
-       rspamd_mempool_delete (spf_module_ctx->spf_pool);
        rspamd_lru_hash_destroy (spf_module_ctx->spf_hash);
        rspamd_map_helper_destroy_radix (spf_module_ctx->whitelist_ip);
        memset (spf_module_ctx, 0, sizeof (*spf_module_ctx));
        spf_module_ctx->ctx = saved_ctx;
-       spf_module_ctx->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
-
        return spf_module_config (cfg);
 }
 
index bfb6f4e82f0aa532edf516cd37cee6f31a627fe4..a4507ae71d16bdb2a2aff92df5758abe5664d1aa 100644 (file)
@@ -88,7 +88,6 @@ struct surbl_ctx {
        guint max_redirected_urls;
        gint redirector_cbid;
        struct upstream_list *redirectors;
-       rspamd_mempool_t *surbl_pool;
 };
 
 struct suffix_item {
@@ -403,8 +402,6 @@ surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
 
        surbl_module_ctx->use_redirector = 0;
        surbl_module_ctx->suffixes = NULL;
-       surbl_module_ctx->surbl_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
-                       NULL);
 
        surbl_module_ctx->redirectors = NULL;
        surbl_module_ctx->whitelist = NULL;
@@ -639,15 +636,15 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                        continue;
                }
 
-               new_suffix = rspamd_mempool_alloc0 (surbl_module_ctx->surbl_pool,
+               new_suffix = rspamd_mempool_alloc0 (cfg->cfg_pool,
                                sizeof (struct suffix_item));
                new_suffix->magic = rspamd_surbl_cb_magic;
                new_suffix->suffix = rspamd_mempool_strdup (
-                               surbl_module_ctx->surbl_pool, ucl_obj_tostring (cur));
+                               cfg->cfg_pool, ucl_obj_tostring (cur));
                new_suffix->options = 0;
                new_suffix->bits = g_array_new (FALSE, FALSE,
                                sizeof (struct surbl_bit_item));
-               rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
+               rspamd_mempool_add_destructor (cfg->cfg_pool,
                                (rspamd_mempool_destruct_t )rspamd_array_free_hard,
                                new_suffix->bits);
 
@@ -655,7 +652,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                if (cur == NULL) {
                        if (ucl_object_key (value)) {
                                new_suffix->symbol = rspamd_mempool_strdup (
-                                               surbl_module_ctx->surbl_pool,
+                                               cfg->cfg_pool,
                                                ucl_object_key (value));
                        }
                        else {
@@ -663,12 +660,12 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                                                "surbl rule for suffix %s lacks symbol, using %s as symbol",
                                                new_suffix->suffix, DEFAULT_SURBL_SYMBOL);
                                new_suffix->symbol = rspamd_mempool_strdup (
-                                               surbl_module_ctx->surbl_pool, DEFAULT_SURBL_SYMBOL);
+                                               cfg->cfg_pool, DEFAULT_SURBL_SYMBOL);
                        }
                }
                else {
                        new_suffix->symbol = rspamd_mempool_strdup (
-                                       surbl_module_ctx->surbl_pool, ucl_obj_tostring (cur));
+                                       cfg->cfg_pool, ucl_obj_tostring (cur));
                }
 
                cur = ucl_object_lookup (cur_rule, "options");
@@ -712,7 +709,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                ucl_object_insert_key (ropts,
                                ucl_object_fromstring ("nxdomain"),
                                "rcode", 0, false);
-               rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
+               rspamd_mempool_add_destructor (cfg->cfg_pool,
                                (rspamd_mempool_destruct_t )ucl_object_unref,
                                ropts);
 
@@ -751,11 +748,11 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                                        gchar* p;
                                        bit = ucl_obj_toint (cur_bit);
                                        new_bit = rspamd_mempool_alloc (
-                                                       surbl_module_ctx->surbl_pool,
+                                                       cfg->cfg_pool,
                                                        sizeof(struct surbl_bit_item));
                                        new_bit->bit = bit;
                                        new_bit->symbol = rspamd_mempool_strdup (
-                                                       surbl_module_ctx->surbl_pool,
+                                                       cfg->cfg_pool,
                                                        ucl_object_key (cur_bit));
                                        /* Convert to uppercase */
                                        p = new_bit->symbol;
@@ -779,7 +776,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                        guint32 bit;
 
                        new_suffix->ips = g_hash_table_new (g_int_hash, g_int_equal);
-                       rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
+                       rspamd_mempool_add_destructor (cfg->cfg_pool,
                                        (rspamd_mempool_destruct_t )g_hash_table_unref,
                                        new_suffix->ips);
 
@@ -788,7 +785,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                                        gchar* p;
                                        ip_val = ucl_obj_tostring (cur_bit);
                                        new_bit = rspamd_mempool_alloc (
-                                                       surbl_module_ctx->surbl_pool,
+                                                       cfg->cfg_pool,
                                                        sizeof(struct surbl_bit_item));
                                        if (inet_pton (AF_INET, ip_val, &bit) != 1) {
                                                msg_err_config ("cannot parse ip %s: %s", ip_val,
@@ -797,7 +794,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
                                        }
                                        new_bit->bit = bit;
                                        new_bit->symbol = rspamd_mempool_strdup (
-                                                       surbl_module_ctx->surbl_pool,
+                                                       cfg->cfg_pool,
                                                        ucl_object_key (cur_bit));
                                        /* Convert to uppercase */
                                        p = new_bit->symbol;
@@ -925,7 +922,7 @@ surbl_module_config (struct rspamd_config *cfg)
        if ((value =
                rspamd_config_get_module_opt (cfg, "surbl", "redirector")) != NULL) {
                surbl_module_ctx->redirectors = rspamd_upstreams_create (cfg->ups_ctx);
-               rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
+               rspamd_mempool_add_destructor (cfg->cfg_pool,
                                (rspamd_mempool_destruct_t)rspamd_upstreams_destroy,
                                surbl_module_ctx->redirectors);
                LL_FOREACH (value, cur)
@@ -1044,7 +1041,7 @@ surbl_module_config (struct rspamd_config *cfg)
        }
 
        if (surbl_module_ctx->suffixes != NULL) {
-               rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
+               rspamd_mempool_add_destructor (cfg->cfg_pool,
                        (rspamd_mempool_destruct_t) g_list_free,
                        surbl_module_ctx->suffixes);
        }
@@ -1074,19 +1071,15 @@ surbl_module_config (struct rspamd_config *cfg)
 gint
 surbl_module_reconfig (struct rspamd_config *cfg)
 {
-       /* Delete pool and objects */
-       rspamd_mempool_delete (surbl_module_ctx->surbl_pool);
        /* Reinit module */
        surbl_module_ctx->use_redirector = 0;
        surbl_module_ctx->suffixes = NULL;
-       surbl_module_ctx->surbl_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
-
        surbl_module_ctx->redirectors = NULL;
        surbl_module_ctx->whitelist = NULL;
        /* Zero exceptions hashes */
        surbl_module_ctx->exceptions = NULL;
 
-       rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool,
+       rspamd_mempool_add_destructor (cfg->cfg_pool,
                (rspamd_mempool_destruct_t) g_list_free,
                surbl_module_ctx->suffixes);