diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-26 16:59:33 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-26 16:59:33 +0000 |
commit | 62c2acacbb8edf6cb58b16daaf98004d93711bd1 (patch) | |
tree | 7bac1a71e9d9b9b115eda15499ba5b120a74671a /src | |
parent | 19d4b6437d113c522d6fd0bff0a7c31dd31b86e8 (diff) | |
download | rspamd-62c2acacbb8edf6cb58b16daaf98004d93711bd1.tar.gz rspamd-62c2acacbb8edf6cb58b16daaf98004d93711bd1.zip |
Fix multiple regexp in the cache for lua API
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/re_cache.c | 2 | ||||
-rw-r--r-- | src/lua/lua_config.c | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index 3174465bd..6b86dc9e0 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -316,7 +316,6 @@ rspamd_re_cache_init (struct rspamd_re_cache *cache, struct rspamd_config *cfg) re_class = rspamd_regexp_get_class (re); g_assert (re_class != NULL); rspamd_regexp_set_cache_id (re, i); - msg_info_re_cache ("HUI: %d -> %s", i, rspamd_regexp_get_pattern (re)); if (re_class->st == NULL) { re_class->st = g_slice_alloc (sizeof (*re_class->st)); @@ -1143,7 +1142,6 @@ rspamd_re_cache_compile_hyperscan (struct rspamd_re_cache *cache, else { hs_ids[i] = rspamd_regexp_get_cache_id (re); hs_pats[i] = rspamd_regexp_get_pattern (re); - msg_info_re_cache("HUI: %d -> %s", hs_ids[i], hs_pats[i]); i ++; hs_free_database (test_db); } diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 447125a87..f867cfabe 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1564,6 +1564,7 @@ lua_config_register_regexp (lua_State *L) { struct rspamd_config *cfg = lua_check_config (L, 1); struct rspamd_lua_regexp *re = NULL; + rspamd_regexp_t *cache_re; const gchar *type_str = NULL, *header_str = NULL; gsize header_len = 0; GError *err = NULL; @@ -1613,8 +1614,25 @@ lua_config_register_regexp (lua_State *L) header_len = strlen (header_str) + 1; } - rspamd_re_cache_add (cfg->re_cache, re->re, type, + cache_re = rspamd_re_cache_add (cfg->re_cache, re->re, type, (gpointer) header_str, header_len); + + /* + * XXX: here are dragons! + * Actually, lua regexp contains internal rspamd_regexp_t + * and it owns it. + * However, after this operation we have some OTHER regexp, + * which we really would like to use. + * So we do the following: + * 1) Remove old re and unref it + * 2) Replace the internal re with cached one + * 3) Increase its refcount to share ownership between cache and + * lua object + */ + if (cache_re != re->re) { + rspamd_regexp_unref (re->re); + re->re = rspamd_regexp_ref (cache_re); + } } } } |