Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions apache2/msc_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,
return NULL;
}

/* Register the cleanup as soon as there is something to free, so the
* compiled pattern is released even if a later step fails (#2407). */
regex->match_context = NULL;
apr_pool_cleanup_register(pool, (void *)regex,
(apr_status_t (*)(void *))msc_pcre_cleanup, apr_pool_cleanup_null);

#ifdef WITH_PCRE_JIT
regex->jit_compile_rc = pcre2_jit_compile(regex->re, PCRE2_JIT_COMPLETE);
#endif

/* Setup the pcre2 match context */
regex->match_context = NULL;
match_context = pcre2_match_context_create(NULL);
if (match_context == NULL) {
return NULL;
Expand Down Expand Up @@ -131,9 +136,6 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,

regex->match_context = match_context;

apr_pool_cleanup_register(pool, (void *)regex,
(apr_status_t (*)(void *))msc_pcre_cleanup, apr_pool_cleanup_null);

return regex;
}
#else /* not WITH_PCRE2 */
Expand All @@ -154,6 +156,10 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,
}
if (regex->re == NULL) return NULL;

/* Register the cleanup as soon as there is something to free (#2407). */
apr_pool_cleanup_register(pool, (void *)regex,
(apr_status_t (*)(void *))msc_pcre_cleanup, apr_pool_cleanup_null);

#ifdef WITH_PCRE_STUDY
#ifdef WITH_PCRE_JIT
pe = pcre_study(regex->re, PCRE_STUDY_JIT_COMPILE, &errptr);
Expand Down Expand Up @@ -211,9 +217,6 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,

regex->pe = pe;

apr_pool_cleanup_register(pool, (void *)regex,
(apr_status_t (*)(void *))msc_pcre_cleanup, apr_pool_cleanup_null);

return regex;
}
#endif /* WITH_PCRE2 */
Expand Down
Loading