aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-17 16:53:20 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-17 16:53:20 +0000
commit6ff5a8debb423d1c7b62f18833cdd500876848af (patch)
tree25e76b93869c9c844aacda9c7ba34e0f8eab299d /src/plugins
parent5dd52de750ce5dfbbe182d204d0a66498bc69a9a (diff)
downloadrspamd-6ff5a8debb423d1c7b62f18833cdd500876848af.tar.gz
rspamd-6ff5a8debb423d1c7b62f18833cdd500876848af.zip
[Fix] Fix memory leak on reload in plugins
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/chartable.c8
-rw-r--r--src/plugins/dkim_check.c22
-rw-r--r--src/plugins/fuzzy_check.c15
-rw-r--r--src/plugins/regexp.c7
-rw-r--r--src/plugins/spf.c6
5 files changed, 35 insertions, 23 deletions
diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c
index bfc5d2378..3b5a0f717 100644
--- a/src/plugins/chartable.c
+++ b/src/plugins/chartable.c
@@ -78,10 +78,12 @@ static void chartable_url_symbol_callback (struct rspamd_task *task, void *unuse
gint
chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
- chartable_module_ctx = g_malloc (sizeof (struct chartable_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;
+ chartable_module_ctx->chartable_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ chartable_module_ctx->max_word_len = 10;
+ }
*ctx = (struct module_ctx *)chartable_module_ctx;
diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c
index 039c12c3f..6b10b2aa9 100644
--- a/src/plugins/dkim_check.c
+++ b/src/plugins/dkim_check.c
@@ -115,16 +115,18 @@ dkim_module_key_dtor (gpointer k)
gint
dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
- 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 = "from:sender:reply-to:subject:date:message-id:"
- "to:cc:mime-version:content-type:content-transfer-encoding:"
- "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:"
- "in-reply-to:references:list-id:list-owner:list-unsubscribe:"
- "list-subscribe:list-post";
- dkim_module_ctx->sign_condition_ref = -1;
- dkim_module_ctx->max_sigs = DEFAULT_MAX_SIGS;
+ 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 = "from:sender:reply-to:subject:date:message-id:"
+ "to:cc:mime-version:content-type:content-transfer-encoding:"
+ "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:"
+ "in-reply-to:references:list-id:list-owner:list-unsubscribe:"
+ "list-subscribe:list-post";
+ dkim_module_ctx->sign_condition_ref = -1;
+ dkim_module_ctx->max_sigs = DEFAULT_MAX_SIGS;
+ }
*ctx = (struct module_ctx *)dkim_module_ctx;
diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c
index 26ad295fa..e6a7b1bc1 100644
--- a/src/plugins/fuzzy_check.c
+++ b/src/plugins/fuzzy_check.c
@@ -637,13 +637,16 @@ fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
lua_State *L = cfg->lua_state;
- fuzzy_module_ctx = g_malloc0 (sizeof (struct fuzzy_ctx));
+ if (fuzzy_module_ctx == NULL) {
+ fuzzy_module_ctx = g_malloc0 (sizeof (struct fuzzy_ctx));
+
+ fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ /* TODO: this should match rules count actually */
+ fuzzy_module_ctx->keypairs_cache = rspamd_keypair_cache_new (32);
+ fuzzy_module_ctx->fuzzy_rules = g_ptr_array_new ();
+ }
- fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
fuzzy_module_ctx->cfg = cfg;
- /* TODO: this should match rules count actually */
- fuzzy_module_ctx->keypairs_cache = rspamd_keypair_cache_new (32);
- fuzzy_module_ctx->fuzzy_rules = g_ptr_array_new ();
*ctx = (struct module_ctx *)fuzzy_module_ctx;
@@ -1043,10 +1046,12 @@ fuzzy_check_module_reconfig (struct rspamd_config *cfg)
saved_ctx = fuzzy_module_ctx->ctx;
rspamd_mempool_delete (fuzzy_module_ctx->fuzzy_pool);
rspamd_keypair_cache_destroy (fuzzy_module_ctx->keypairs_cache);
+ g_ptr_array_free (fuzzy_module_ctx->fuzzy_rules, TRUE);
memset (fuzzy_module_ctx, 0, sizeof (*fuzzy_module_ctx));
fuzzy_module_ctx->ctx = saved_ctx;
fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
fuzzy_module_ctx->cfg = cfg;
+ fuzzy_module_ctx->fuzzy_rules = g_ptr_array_new ();
fuzzy_module_ctx->keypairs_cache = rspamd_keypair_cache_new (32);
return fuzzy_check_module_config (cfg);
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c
index a88bde21b..f2d3ab2c3 100644
--- a/src/plugins/regexp.c
+++ b/src/plugins/regexp.c
@@ -91,9 +91,10 @@ read_regexp_expression (rspamd_mempool_t * pool,
gint
regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
- regexp_module_ctx = g_malloc (sizeof (struct regexp_ctx));
-
- regexp_module_ctx->regexp_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ if (regexp_module_ctx == NULL) {
+ regexp_module_ctx = g_malloc (sizeof (struct regexp_ctx));
+ regexp_module_ctx->regexp_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ }
*ctx = (struct module_ctx *)regexp_module_ctx;
diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index e51016429..15ebdab31 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -83,9 +83,11 @@ module_t spf_module = {
gint
spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
- spf_module_ctx = g_malloc (sizeof (struct spf_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->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ }
*ctx = (struct module_ctx *)spf_module_ctx;