From ceb133b5e603c04cfa5c8da8851c8134523e0ee9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 18 Nov 2015 15:19:36 +0000 Subject: [PATCH] Fix issues found --- src/libserver/cfg_utils.c | 3 +++ src/lua/lua_util.c | 14 +++++--------- src/rspamadm/configdump.c | 12 +----------- src/rspamadm/configtest.c | 14 +------------- src/rspamadm/rspamadm.c | 5 ++--- src/rspamd.c | 3 ++- 6 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 5d0eb06ae..4146d51cb 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -199,6 +199,8 @@ rspamd_config_defaults (void) cfg->cache = rspamd_symbols_cache_new (cfg); REF_INIT_RETAIN (cfg, rspamd_config_free); + + return cfg; } void @@ -228,6 +230,7 @@ rspamd_config_free (struct rspamd_config *cfg) rspamd_symbols_cache_destroy (cfg->cache); REF_RELEASE (cfg->libs_ctx); rspamd_mempool_delete (cfg->cfg_pool); + g_slice_free1 (sizeof (*cfg), cfg); } const ucl_object_t * diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index f0c9369bf..6a43206a5 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -161,17 +161,14 @@ lua_util_load_rspamd_config (lua_State *L) cfg_name = luaL_checkstring (L, 1); if (cfg_name) { - cfg = g_malloc0 (sizeof (struct rspamd_config)); - rspamd_init_cfg (cfg, FALSE); - cfg->cache = rspamd_symbols_cache_new (cfg); + cfg = rspamd_config_defaults (); if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL, NULL)) { msg_err_config ("cannot load config from %s", cfg_name); lua_pushnil (L); } else { - rspamd_config_post_load (cfg); - rspamd_symbols_cache_init (cfg->cache); + rspamd_config_post_load (cfg, FALSE); pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *)); rspamd_lua_setclass (L, "rspamd{config}", -1); *pcfg = cfg; @@ -193,8 +190,8 @@ lua_util_config_from_ucl (lua_State *L) if (obj) { cfg = g_malloc0 (sizeof (struct rspamd_config)); - rspamd_init_cfg (cfg, FALSE); - cfg->lua_state = L; + cfg = rspamd_config_defaults (); + cfg->rcl_obj = obj; cfg->cache = rspamd_symbols_cache_new (cfg); top = rspamd_rcl_config_init (); @@ -205,8 +202,7 @@ lua_util_config_from_ucl (lua_State *L) lua_pushnil (L); } else { - rspamd_config_post_load (cfg); - rspamd_symbols_cache_init (cfg->cache); + rspamd_config_post_load (cfg, FALSE); pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *)); rspamd_lua_setclass (L, "rspamd{config}", -1); *pcfg = cfg; diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c index d19d2da33..e40f2f34a 100644 --- a/src/rspamadm/configdump.c +++ b/src/rspamadm/configdump.c @@ -173,25 +173,15 @@ rspamadm_configdump (gint argc, gchar **argv) } else { /* Do post-load actions */ - rspamd_config_post_load (cfg); + rspamd_config_post_load (cfg, FALSE); ret = TRUE; } if (ret) { - rspamd_symbols_cache_init (rspamd_main->cfg->cache); if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { ret = FALSE; } - - /* Insert classifiers symbols */ - (void) rspamd_config_insert_classify_symbols (rspamd_main->cfg); - - if (!rspamd_symbols_cache_validate (rspamd_main->cfg->cache, - rspamd_main->cfg, - FALSE)) { - ret = FALSE; - } } if (ret) { diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c index 1de694975..65f358f66 100644 --- a/src/rspamadm/configtest.c +++ b/src/rspamadm/configtest.c @@ -150,25 +150,13 @@ rspamadm_configtest (gint argc, gchar **argv) } else { /* Do post-load actions */ - rspamd_config_post_load (cfg); - ret = TRUE; + ret = rspamd_config_post_load (cfg, TRUE); } if (ret) { - rspamd_symbols_cache_init (rspamd_main->cfg->cache); - if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { ret = FALSE; } - - /* Insert classifiers symbols */ - (void) rspamd_config_insert_classify_symbols (rspamd_main->cfg); - - if (!rspamd_symbols_cache_validate (rspamd_main->cfg->cache, - rspamd_main->cfg, - FALSE)) { - ret = FALSE; - } } if (strict && ret) { diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index c4ae62a4b..5751c50d0 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -208,10 +208,9 @@ main (gint argc, gchar **argv, gchar **env) rspamd_strcase_equal, g_free, g_free); ottery_init (NULL); process_quark = g_quark_from_static_string ("rspamadm"); - cfg = g_malloc0 (sizeof (*cfg)); + cfg = rspamd_config_defaults (); + cfg->libs_ctx = rspamd_init_libs (); rspamd_main = g_malloc0 (sizeof (*rspamd_main)); - rspamd_init_libs (); - rspamd_init_cfg (cfg, TRUE); rspamd_main->cfg = cfg; rspamd_main->pid = getpid (); rspamd_main->type = process_quark; diff --git a/src/rspamd.c b/src/rspamd.c index 3d42f2650..92b17b37e 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -270,7 +270,8 @@ reread_config (struct rspamd_main *rspamd_main) tmp_cfg = rspamd_config_defaults (); tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules); - tmp_cfg->libs_ctx = REF_RETAIN (rspamd_main->cfg->libs_ctx); + tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx; + REF_RETAIN (tmp_cfg->libs_ctx); rspamd_set_logger (tmp_cfg, g_quark_try_string ("main"), rspamd_main); cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool, rspamd_main->cfg->cfg_name); -- 2.39.5