From: Vsevolod Stakhov Date: Tue, 8 Dec 2015 16:03:31 +0000 (+0000) Subject: Fix replacing regexps in the cache X-Git-Tag: 1.1.0~375 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9ca3adcab96acb33f1629847b6e0281f82a6f01;p=thirdparty%2Frspamd.git Fix replacing regexps in the cache --- diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 69597c1d1e..4347c21002 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -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));