aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/regexp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-09-18 20:24:42 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-09-18 20:24:42 +0100
commit9af2911e8dfa989bcdbf1e3aa2eb999f3f6b7dad (patch)
tree9edc4c667ec8082d6d467af21ef57ea4412bcf0d /src/libutil/regexp.c
parent2d80fdad5fb5e918a5bbe8385fafb67eb7e4797a (diff)
downloadrspamd-9af2911e8dfa989bcdbf1e3aa2eb999f3f6b7dad.tar.gz
rspamd-9af2911e8dfa989bcdbf1e3aa2eb999f3f6b7dad.zip
[Fix] Plug memory leak in regexp destruction with pcre2
Diffstat (limited to 'src/libutil/regexp.c')
-rw-r--r--src/libutil/regexp.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index 534187f37..70a50872a 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -116,28 +116,33 @@ rspamd_regexp_dtor (rspamd_regexp_t *re)
if (re) {
if (re->raw_re && re->raw_re != re->re) {
#ifndef WITH_PCRE2
-#ifdef HAVE_PCRE_JIT
+ /* PCRE1 version */
+# ifdef HAVE_PCRE_JIT
if (re->raw_extra) {
pcre_free_study (re->raw_extra);
}
-#endif
+# endif
#else
- if (re->mcontext) {
- pcre2_match_context_free (re->mcontext);
+ /* PCRE 2 version */
+ if (re->raw_mcontext) {
+ pcre2_match_context_free (re->raw_mcontext);
}
#endif
PCRE_FREE (re->raw_re);
}
+
if (re->re) {
#ifndef WITH_PCRE2
-#ifdef HAVE_PCRE_JIT
+ /* PCRE1 version */
+# ifdef HAVE_PCRE_JIT
if (re->extra) {
pcre_free_study (re->extra);
}
-#endif
+# endif
#else
- if (re->raw_mcontext) {
- pcre2_match_context_free (re->raw_mcontext);
+ /* PCRE 2 version */
+ if (re->mcontext) {
+ pcre2_match_context_free (re->mcontext);
}
#endif
PCRE_FREE (re->re);
@@ -169,15 +174,18 @@ rspamd_regexp_post_process (rspamd_regexp_t *r)
pcre2_set_recursion_limit (r->mcontext, max_recursion_depth);
pcre2_set_match_limit (r->mcontext, max_backtrack);
- if (r->re != r->raw_re) {
+ if (r->raw_re && r->re != r->raw_re) {
r->raw_mcontext = pcre2_match_context_create (NULL);
g_assert (r->raw_mcontext != NULL);
pcre2_set_recursion_limit (r->raw_mcontext, max_recursion_depth);
pcre2_set_match_limit (r->raw_mcontext, max_backtrack);
}
- else {
+ else if (r->raw_re) {
r->raw_mcontext = r->mcontext;
}
+ else {
+ r->raw_mcontext = NULL;
+ }
#ifdef HAVE_PCRE_JIT
if (can_jit) {