]> source.dussan.org Git - rspamd.git/commitdiff
Fix replacing regexps in the cache
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 8 Dec 2015 16:03:31 +0000 (16:03 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 8 Dec 2015 16:03:31 +0000 (16:03 +0000)
src/libserver/re_cache.c

index 69597c1d1e5de25e9b2e2d6e99a58a2ab4c3f59b..4347c210023c17c8c6aa5e5a40e5d61e85180836 100644 (file)
@@ -233,27 +233,25 @@ rspamd_re_cache_replace (struct rspamd_re_cache *cache,
                re_id = rspamd_regexp_get_cache_id (what);
 
                g_assert (re_id != RSPAMD_INVALID_ID);
-               src = g_hash_table_lookup (re_class->re, what);
+               src = g_hash_table_lookup (re_class->re, rspamd_regexp_get_id (what));
                elt = g_ptr_array_index (cache->re, re_id);
-
-               if (src) {
-                       rspamd_regexp_set_cache_id (what, RSPAMD_INVALID_ID);
-                       rspamd_regexp_set_class (what, NULL);
-                       rspamd_regexp_set_cache_id (with, re_id);
-                       rspamd_regexp_set_class (with, re_class);
-                       /*
-                        * On calling of this function, we actually unref old re (what)
-                        */
-                       g_hash_table_insert (re_class->re,
-                                       rspamd_regexp_get_id (what),
-                                       rspamd_regexp_ref (with));
-               }
-
-               if (elt) {
-                       rspamd_regexp_unref (elt->re);
-                       elt->re = rspamd_regexp_ref (with);
-                       /* XXX: do not touch match type here */
-               }
+               g_assert (elt != NULL);
+               g_assert (src != NULL);
+
+               rspamd_regexp_set_cache_id (what, RSPAMD_INVALID_ID);
+               rspamd_regexp_set_class (what, NULL);
+               rspamd_regexp_set_cache_id (with, re_id);
+               rspamd_regexp_set_class (with, re_class);
+               /*
+                * On calling of this function, we actually unref old re (what)
+                */
+               g_hash_table_insert (re_class->re,
+                               rspamd_regexp_get_id (what),
+                               rspamd_regexp_ref (with));
+
+               rspamd_regexp_unref (elt->re);
+               elt->re = rspamd_regexp_ref (with);
+               /* XXX: do not touch match type here */
        }
 }
 
@@ -287,8 +285,9 @@ rspamd_re_cache_init (struct rspamd_re_cache *cache)
        for (i = 0; i < cache->re->len; i ++) {
                elt = g_ptr_array_index (cache->re, i);
                re = elt->re;
-               rspamd_regexp_set_cache_id (re, i);
                re_class = rspamd_regexp_get_class (re);
+               g_assert (re_class != NULL);
+               rspamd_regexp_set_cache_id (re, i);
 
                if (re_class->st == NULL) {
                        re_class->st = g_slice_alloc (sizeof (*re_class->st));