From 0c445cda06d5e84d6181c65eb02b9b9953d0729b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 17 Jan 2017 17:45:05 +0000 Subject: [PATCH] [Fix] More random fixes for reload... --- src/fuzzy_storage.c | 3 -- src/libmime/mime_expressions.c | 2 - src/libserver/cfg_rcl.c | 2 + src/log_helper.c | 2 +- src/rspamd_proxy.c | 73 +++++++++++++--------------------- src/worker.c | 6 +-- 6 files changed, 31 insertions(+), 57 deletions(-) diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 7a980ceef..01f00fe58 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -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); } diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index e8a3134c7..47dda6c05 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -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 = '/'; diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index b4bb4c38d..ee54be39b 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -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 { diff --git a/src/log_helper.c b/src/log_helper.c index 33a1a0ae5..974649d87 100644 --- a/src/log_helper.c +++ b/src/log_helper.c @@ -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; diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 8e2b205b7..df92dab1c 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -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); diff --git a/src/worker.c b/src/worker.c index bf50e5210..94ef2c9d1 100644 --- a/src/worker.c +++ b/src/worker.c @@ -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) { -- 2.39.5