]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Do not allocate non-unique options
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jun 2021 16:25:29 +0000 (17:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jun 2021 16:25:29 +0000 (17:25 +0100)
src/libmime/scan_result.c

index 0256ab4858b3d4b98f48099f1a80dce11a6b143f..e7fab8c6dda9379130a3da19424a73c69f0e1851 100644 (file)
@@ -724,22 +724,30 @@ rspamd_task_add_result_option (struct rspamd_task *task,
 
                        if (!(cur->sym && (cur->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM)) &&
                                kh_size (cur->options) < task->cfg->default_max_shots) {
-                               opt_cpy = rspamd_task_option_safe_copy (task, val, vlen, &cpy_len);
-                               /* Append new options */
-                               srch.option = (gchar *) opt_cpy;
-                               srch.optlen = cpy_len;
+
+                               srch.option = (gchar *) val;
+                               srch.optlen = vlen;
                                k = kh_get (rspamd_options_hash, cur->options, &srch);
 
                                if (k == kh_end (cur->options)) {
-                                       opt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*opt));
-                                       opt->optlen = cpy_len;
-                                       opt->option = opt_cpy;
+                                       opt_cpy = rspamd_task_option_safe_copy (task, val, vlen, &cpy_len);
+                                       if (cpy_len != vlen) {
+                                               srch.option = (gchar *) opt_cpy;
+                                               srch.optlen = cpy_len;
+                                               k = kh_get (rspamd_options_hash, cur->options, &srch);
+                                       }
+                                       /* Append new options */
+                                       if (k == kh_end (cur->options)) {
+                                               opt = rspamd_mempool_alloc0 (task->task_pool, sizeof(*opt));
+                                               opt->optlen = cpy_len;
+                                               opt->option = opt_cpy;
 
-                                       kh_put (rspamd_options_hash, cur->options, opt, &r);
-                                       DL_APPEND (cur->opts_head, opt);
+                                               kh_put (rspamd_options_hash, cur->options, opt, &r);
+                                               DL_APPEND (cur->opts_head, opt);
 
-                                       if (s == cur) {
-                                               ret = TRUE;
+                                               if (s == cur) {
+                                                       ret = TRUE;
+                                               }
                                        }
                                }
                        }