]> source.dussan.org Git - rspamd.git/commitdiff
Fix another issues with raw/utf regexps.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 13 May 2015 12:00:52 +0000 (13:00 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 13 May 2015 12:00:52 +0000 (13:00 +0100)
src/libutil/regexp.c

index deaca80a5ba7a948561b9190e5709a3e14c9d92d..02ece3350093d4bf8615219bf232b6d9b8dc9705 100644 (file)
@@ -87,6 +87,19 @@ static void
 rspamd_regexp_dtor (rspamd_regexp_t *re)
 {
        if (re) {
+               if (re->raw_re && re->raw_re != re->re) {
+                       pcre_free (re->raw_re);
+#ifdef HAVE_PCRE_JIT
+                       if (re->raw_extra) {
+                               pcre_free_study (re->raw_extra);
+                       }
+                       if (re->raw_jstack) {
+                               pcre_jit_stack_free (re->raw_jstack);
+                       }
+#else
+                       pcre_free (re->raw_extra);
+#endif
+               }
                if (re->re) {
                        pcre_free (re->re);
 #ifdef HAVE_PCRE_JIT
@@ -100,19 +113,6 @@ rspamd_regexp_dtor (rspamd_regexp_t *re)
                        pcre_free (re->extra);
 #endif
                }
-               if (re->raw_re) {
-                       pcre_free (re->raw_re);
-#ifdef HAVE_PCRE_JIT
-                       if (re->raw_extra) {
-                               pcre_free_study (re->raw_extra);
-                       }
-                       if (re->raw_jstack) {
-                               pcre_jit_stack_free (re->raw_jstack);
-                       }
-#else
-                       pcre_free (re->raw_extra);
-#endif
-               }
 
                if (re->pattern) {
                        g_free (re->pattern);
@@ -274,7 +274,7 @@ fin:
                                                        PCRE_INFO_JIT, &jit);
 
                                        if (n != 0 || jit != 1) {
-                                               msg_info ("jit compilation of %s is not supported", pattern);
+                                               msg_debug ("jit compilation of %s is not supported", pattern);
                                                res->jstack = NULL;
                                        }
                                        else {
@@ -289,31 +289,42 @@ fin:
                                                pattern, err_str);
                        }
                }
+
                if (res->raw_re) {
-                       res->raw_extra = pcre_study (res->raw_re, study_flags, &err_str);
-                       if (res->raw_extra != NULL) {
+                       if (res->raw_re != res->re) {
+                               res->raw_extra = pcre_study (res->raw_re, study_flags, &err_str);
+                               if (res->raw_extra != NULL) {
 #ifdef HAVE_PCRE_JIT
-                               gint jit, n;
-
-                               if (can_jit) {
-                                       jit = 0;
-                                       n = pcre_fullinfo (res->re, res->extra,
-                                                       PCRE_INFO_JIT, &jit);
-
-                                       if (n != 0 || jit != 1) {
-                                               msg_info ("jit compilation of %s is not supported", pattern);
-                                               res->jstack = NULL;
-                                       }
-                                       else {
-                                               res->jstack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024);
-                                               pcre_assign_jit_stack (res->extra, NULL, res->jstack);
+                                       gint jit, n;
+
+                                       if (can_jit) {
+                                               jit = 0;
+                                               n = pcre_fullinfo (res->raw_re, res->raw_extra,
+                                                               PCRE_INFO_JIT, &jit);
+
+                                               if (n != 0 || jit != 1) {
+                                                       msg_debug ("jit compilation of %s is not supported",
+                                                                       pattern);
+                                                       res->raw_jstack = NULL;
+                                               }
+                                               else {
+                                                       res->raw_jstack = pcre_jit_stack_alloc (32 * 1024,
+                                                                       512 * 1024);
+                                                       pcre_assign_jit_stack (res->raw_extra, NULL,
+                                                                       res->raw_jstack);
+                                               }
                                        }
-                               }
 #endif
+                               }
+                               else {
+                                       msg_warn ("cannot optimize raw regexp pattern: '%s': %s",
+                                                       pattern, err_str);
+                               }
                        }
                        else {
-                               msg_warn ("cannot optimize raw regexp pattern: '%s': %s",
-                                               pattern, err_str);
+                               /* Just alias pointers */
+                               res->raw_extra = res->extra;
+                               res->raw_jstack = res->jstack;
                        }
                }
        }