]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Try better to keep cached records alive
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 1 Feb 2019 12:16:07 +0000 (12:16 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 1 Feb 2019 12:16:07 +0000 (12:16 +0000)
src/plugins/dkim_check.c
src/plugins/spf.c

index a203edc3d0c6661322e242161877a593f83496e9..92354529fcf6e9f44d4cdfb3ed2ae0d7a75819c5 100644 (file)
@@ -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);
index eedaf6c2e35b168b9bfe4dabf0a05b26a5a0847b..dfdf110a12cda1022ec6810a51b2f7dae0acb89e 100644 (file)
@@ -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);