commit 34befc7: [Minor] Try better to keep cached records alive
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Feb 1 12:21:06 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-02-01 12:16:07 +0000
URL: https://github.com/rspamd/rspamd/commit/34befc7a81392cbd9a412eec4894d90e4a1b2d03 (HEAD -> master)
[Minor] Try better to keep cached records alive
---
src/plugins/dkim_check.c | 26 ++++++++++++++------------
src/plugins/spf.c | 4 ++++
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c
index a203edc3d..92354529f 100644
--- a/src/plugins/dkim_check.c
+++ b/src/plugins/dkim_check.c
@@ -1100,6 +1100,8 @@ dkim_module_key_handler (rspamd_dkim_key_t *key,
dkim_module_ctx = dkim_get_context (task->cfg);
if (key != NULL) {
+ /* Another ref belongs to the check context */
+ res->key = rspamd_dkim_key_ref (key);
/*
* We actually receive key with refcount = 1, so we just assume that
* lru hash owns this object now
@@ -1107,8 +1109,6 @@ dkim_module_key_handler (rspamd_dkim_key_t *key,
rspamd_lru_hash_insert (dkim_module_ctx->dkim_hash,
g_strdup (rspamd_dkim_get_dns_key (ctx)),
key, res->task->tv.tv_sec, rspamd_dkim_key_get_ttl (key));
- /* Another ref belongs to the check context */
- res->key = rspamd_dkim_key_ref (key);
/* Release key when task is processed */
rspamd_mempool_add_destructor (res->task->task_pool,
dkim_module_key_dtor, res->key);
@@ -1454,10 +1454,11 @@ dkim_sign_callback (struct rspamd_task *task,
return;
}
-
- rspamd_lru_hash_insert (dkim_module_ctx->dkim_sign_hash,
- g_strdup (lru_key), dkim_key,
- time (NULL), 0);
+ else {
+ rspamd_lru_hash_insert (dkim_module_ctx->dkim_sign_hash,
+ g_strdup (lru_key), dkim_key,
+ time (NULL), 0);
+ }
}
else if (rspamd_dkim_sign_key_maybe_invalidate (dkim_key,
key_sign_type, key, len)) {
@@ -1479,10 +1480,11 @@ dkim_sign_callback (struct rspamd_task *task,
return;
}
-
- rspamd_lru_hash_insert (dkim_module_ctx->dkim_sign_hash,
- g_strdup (lru_key), dkim_key,
- time (NULL), 0);
+ else {
+ rspamd_lru_hash_insert (dkim_module_ctx->dkim_sign_hash,
+ g_strdup (lru_key), dkim_key,
+ time (NULL), 0);
+ }
}
ctx = rspamd_create_dkim_sign_context (task, dkim_key,
@@ -1666,6 +1668,8 @@ dkim_module_lua_on_key (rspamd_dkim_key_t *key,
dkim_module_ctx = dkim_get_context (task->cfg);
if (key != NULL) {
+ /* Another ref belongs to the check context */
+ cbd->key = rspamd_dkim_key_ref (key);
/*
* We actually receive key with refcount = 1, so we just assume that
* lru hash owns this object now
@@ -1673,8 +1677,6 @@ dkim_module_lua_on_key (rspamd_dkim_key_t *key,
rspamd_lru_hash_insert (dkim_module_ctx->dkim_hash,
g_strdup (rspamd_dkim_get_dns_key (ctx)),
key, cbd->task->tv.tv_sec, rspamd_dkim_key_get_ttl (key));
- /* Another ref belongs to the check context */
- cbd->key = rspamd_dkim_key_ref (key);
/* Release key when task is processed */
rspamd_mempool_add_destructor (cbd->task->task_pool,
dkim_module_key_dtor, cbd->key);
diff --git a/src/plugins/spf.c b/src/plugins/spf.c
index eedaf6c2e..dfdf110a1 100644
--- a/src/plugins/spf.c
+++ b/src/plugins/spf.c
@@ -543,6 +543,8 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task,
}
else if (record && record->domain) {
+ spf_record_ref (record);
+
if ((l = rspamd_lru_hash_lookup (spf_module_ctx->spf_hash,
record->domain, task->tv.tv_sec)) == NULL) {
l = record;
@@ -562,6 +564,8 @@ spf_plugin_callback (struct spf_resolved *record, struct rspamd_task *task,
spf_record_ref (l);
spf_check_list (l, task);
spf_record_unref (l);
+
+ spf_record_unref (record);
}
rspamd_symcache_item_async_dec_check (task, item, M);
More information about the Commits
mailing list