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));
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);
}
{
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;
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);
+ }
}
}
}