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/lua | |
parent | 19d4b6437d113c522d6fd0bff0a7c31dd31b86e8 (diff) | |
download | rspamd-62c2acacbb8edf6cb58b16daaf98004d93711bd1.tar.gz rspamd-62c2acacbb8edf6cb58b16daaf98004d93711bd1.zip |
Fix multiple regexp in the cache for lua API
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_config.c | 20 |
1 files changed, 19 insertions, 1 deletions
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); + } } } } |