]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] More random fixes for reload...
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Jan 2017 17:45:05 +0000 (17:45 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Jan 2017 17:45:05 +0000 (17:45 +0000)
src/fuzzy_storage.c
src/libmime/mime_expressions.c
src/libserver/cfg_rcl.c
src/log_helper.c
src/rspamd_proxy.c
src/worker.c

index 7a980ceefc01b83a8d71839868c8646d54cacfac..01f00fe58f7b6878718b233dac23b31f6912b23f 100644 (file)
@@ -237,9 +237,6 @@ fuzzy_key_dtor (gpointer p)
        if (key->stat) {
                fuzzy_key_stat_dtor (key->stat);
        }
-       if (key->key) {
-               rspamd_keypair_unref (key->key);
-       }
 
        g_slice_free1 (sizeof (*key), key);
 }
index e8a3134c7a6bafd05ea5799efe27ed6887123d42..47dda6c05b033afcf9f431566c1b65d7000ebb4c 100644 (file)
@@ -449,8 +449,6 @@ rspamd_mime_expr_parse_regexp_atom (rspamd_mempool_t * pool, const gchar *line,
        }
 
        rspamd_regexp_set_ud (result->regexp, result);
-       rspamd_mempool_add_destructor (pool,
-                       (rspamd_mempool_destruct_t)rspamd_regexp_unref, result->regexp);
 
        *dend = '/';
 
index b4bb4c38d17238f887614a778a43ea6f61e2de93..ee54be39bfc898965a110aac533182be37514836 100644 (file)
@@ -2935,6 +2935,8 @@ rspamd_rcl_parse_struct_keypair (rspamd_mempool_t *pool,
                kp = rspamd_keypair_from_ucl (obj);
 
                if (kp != NULL) {
+                       rspamd_mempool_add_destructor (pool,
+                                       (rspamd_mempool_destruct_t)rspamd_keypair_unref, kp);
                        *target = kp;
                }
                else {
index 33a1a0ae55b9b07446c9055c8f3a3ab78515691f..974649d878123c576e728ef410738dd770ebfc6c 100644 (file)
@@ -64,7 +64,7 @@ init_log_helper (struct rspamd_config *cfg)
        GQuark type;
 
        type = g_quark_try_string ("log_helper");
-       ctx = g_malloc0 (sizeof (*ctx));
+       ctx = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (*ctx));
 
        ctx->magic = rspamd_log_helper_magic;
        ctx->cfg = cfg;
index 8e2b205b7a631c4f1575c55965d871c8c710a2c6..df92dab1c7b1278cbb071de8d9c9a1da9a584713 100644 (file)
@@ -296,10 +296,12 @@ rspamd_proxy_parse_upstream (rspamd_mempool_t *pool,
                return FALSE;
        }
 
-       up = g_slice_alloc0 (sizeof (*up));
+       up = g_malloc0 (sizeof (*up));
+       rspamd_mempool_add_destructor (pool,
+                       (rspamd_mempool_destruct_t)g_free, up);
        up->parser_from_ref = -1;
        up->parser_to_ref = -1;
-       up->name = g_strdup (ucl_object_tostring (elt));
+       up->name = rspamd_mempool_strdup (pool, ucl_object_tostring (elt));
        up->timeout = ctx->timeout;
 
        elt = ucl_object_lookup (obj, "key");
@@ -313,6 +315,9 @@ rspamd_proxy_parse_upstream (rspamd_mempool_t *pool,
 
                        goto err;
                }
+
+               rspamd_mempool_add_destructor (pool,
+                               (rspamd_mempool_destruct_t)rspamd_pubkey_unref, up->key);
        }
 
        elt = ucl_object_lookup (obj, "hosts");
@@ -332,6 +337,9 @@ rspamd_proxy_parse_upstream (rspamd_mempool_t *pool,
                goto err;
        }
 
+       rspamd_mempool_add_destructor (pool,
+                       (rspamd_mempool_destruct_t)rspamd_upstreams_destroy, up->u);
+
        elt = ucl_object_lookup (obj, "default");
        if (elt && ucl_object_toboolean (elt)) {
                ctx->default_upstream = up;
@@ -366,25 +374,6 @@ rspamd_proxy_parse_upstream (rspamd_mempool_t *pool,
        return TRUE;
 
 err:
-
-       if (up) {
-               g_free (up->name);
-               rspamd_upstreams_destroy (up->u);
-
-               if (up->key) {
-                       rspamd_pubkey_unref (up->key);
-               }
-
-               if (up->parser_from_ref != -1) {
-                       luaL_unref (L, LUA_REGISTRYINDEX, up->parser_from_ref);
-               }
-               if (up->parser_to_ref != -1) {
-                       luaL_unref (L, LUA_REGISTRYINDEX, up->parser_to_ref);
-               }
-
-               g_slice_free1 (sizeof (*up), up);
-       }
-
        return FALSE;
 }
 
@@ -419,8 +408,10 @@ rspamd_proxy_parse_mirror (rspamd_mempool_t *pool,
                return FALSE;
        }
 
-       up = g_slice_alloc0 (sizeof (*up));
-       up->name = g_strdup (ucl_object_tostring (elt));
+       up = g_malloc0 (sizeof (*up));
+       rspamd_mempool_add_destructor (pool,
+                               (rspamd_mempool_destruct_t)g_free, up);
+       up->name = rspamd_mempool_strdup (pool, ucl_object_tostring (elt));
        up->parser_to_ref = -1;
        up->parser_from_ref = -1;
        up->timeout = ctx->timeout;
@@ -436,6 +427,9 @@ rspamd_proxy_parse_mirror (rspamd_mempool_t *pool,
 
                        goto err;
                }
+
+               rspamd_mempool_add_destructor (pool,
+                               (rspamd_mempool_destruct_t)rspamd_pubkey_unref, up->key);
        }
 
        elt = ucl_object_lookup (obj, "hosts");
@@ -455,6 +449,9 @@ rspamd_proxy_parse_mirror (rspamd_mempool_t *pool,
                goto err;
        }
 
+       rspamd_mempool_add_destructor (pool,
+                       (rspamd_mempool_destruct_t)rspamd_upstreams_destroy, up->u);
+
        elt = ucl_object_lookup_any (obj, "probability", "prob", NULL);
        if (elt) {
                up->prob = ucl_object_todouble (elt);
@@ -487,7 +484,7 @@ rspamd_proxy_parse_mirror (rspamd_mempool_t *pool,
 
        elt = ucl_object_lookup_any (obj, "settings", "settings_id", NULL);
        if (elt && ucl_object_type (elt) == UCL_STRING) {
-               up->settings_id = g_strdup (ucl_object_tostring (elt));
+               up->settings_id = rspamd_mempool_strdup (pool, ucl_object_tostring (elt));
        }
 
        double_to_tv (up->timeout, &up->io_tv);
@@ -498,24 +495,6 @@ rspamd_proxy_parse_mirror (rspamd_mempool_t *pool,
 
 err:
 
-       if (up) {
-               g_free (up->name);
-               rspamd_upstreams_destroy (up->u);
-
-               if (up->key) {
-                       rspamd_pubkey_unref (up->key);
-               }
-
-               if (up->parser_from_ref != -1) {
-                       luaL_unref (L, LUA_REGISTRYINDEX, up->parser_from_ref);
-               }
-               if (up->parser_to_ref != -1) {
-                       luaL_unref (L, LUA_REGISTRYINDEX, up->parser_to_ref);
-               }
-
-               g_slice_free1 (sizeof (*up), up);
-       }
-
        return FALSE;
 }
 
@@ -625,11 +604,17 @@ init_rspamd_proxy (struct rspamd_config *cfg)
        ctx->magic = rspamd_rspamd_proxy_magic;
        ctx->timeout = 10.0;
        ctx->upstreams = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+       rspamd_mempool_add_destructor (cfg->cfg_pool,
+                       (rspamd_mempool_destruct_t)g_hash_table_unref, ctx->upstreams);
        ctx->mirrors = g_ptr_array_new ();
+       rspamd_mempool_add_destructor (cfg->cfg_pool,
+                       (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard, ctx->mirrors);
        ctx->rotate_tm = DEFAULT_ROTATION_TIME;
        ctx->cfg = cfg;
        ctx->lua_state = cfg->lua_state;
        ctx->cmp_refs = g_array_new (FALSE, FALSE, sizeof (gint));
+       rspamd_mempool_add_destructor (cfg->cfg_pool,
+                       (rspamd_mempool_destruct_t)rspamd_array_free_hard, ctx->cmp_refs);
        ctx->max_retries = DEFAULT_RETRIES;
 
        rspamd_rcl_register_worker_option (cfg,
@@ -1495,10 +1480,6 @@ start_rspamd_proxy (struct rspamd_worker *worker)
 
        rspamd_log_close (worker->srv->logger);
 
-       if (ctx->key) {
-               rspamd_keypair_unref (ctx->key);
-       }
-
        rspamd_keypair_cache_destroy (ctx->keys_cache);
        REF_RELEASE (ctx->cfg);
 
index bf50e5210cf23cad6cb71b1202995d1e1ef75b17..94ef2c9d10e0df2654d78ba5c62a6ea0fda5a4a2 100644 (file)
@@ -488,7 +488,7 @@ init_worker (struct rspamd_config *cfg)
 
        type = g_quark_try_string ("normal");
 
-       ctx = rspamd_mempool_alloc (cfg->cfg_pool,
+       ctx = rspamd_mempool_alloc0 (cfg->cfg_pool,
                        sizeof (struct rspamd_worker_ctx));
 
        ctx->magic = rspamd_worker_magic;
@@ -638,10 +638,6 @@ start_worker (struct rspamd_worker *worker)
        rspamd_stat_close ();
        rspamd_log_close (worker->srv->logger);
 
-       if (ctx->key) {
-               rspamd_keypair_unref (ctx->key);
-       }
-
        rspamd_keypair_cache_destroy (ctx->keys_cache);
 
        DL_FOREACH_SAFE (ctx->log_pipes, lp, ltmp) {