diff --git a/include/common/regex.h b/include/common/regex.h index 762eb56f2..58b9dc14a 100644 --- a/include/common/regex.h +++ b/include/common/regex.h @@ -29,6 +29,12 @@ #ifdef USE_PCRE #include #include + +/* For pre-8.20 PCRE compatibility */ +#ifndef PCRE_STUDY_JIT_COMPILE +#define PCRE_STUDY_JIT_COMPILE 0 +#endif + #else /* no PCRE */ #include #endif @@ -129,9 +135,14 @@ int regex_exec_match2(const struct my_regex *preg, char *subject, int length, static inline void regex_free(struct my_regex *preg) { #if defined(USE_PCRE) || defined(USE_PCRE_JIT) pcre_free(preg->reg); -#ifdef USE_PCRE_JIT +/* PCRE < 8.20 requires pcre_free() while >= 8.20 requires pcre_study_free(), + * which is easily detected using PCRE_CONFIG_JIT. + */ +#ifdef PCRE_CONFIG_JIT pcre_free_study(preg->extra); -#endif +#else /* PCRE_CONFIG_JIT */ + pcre_free(preg->extra); +#endif /* PCRE_CONFIG_JIT */ #else regfree(&preg->regex); #endif diff --git a/src/regex.c b/src/regex.c index c0b23cb12..760a1eda4 100644 --- a/src/regex.c +++ b/src/regex.c @@ -288,16 +288,12 @@ int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char ** return 0; } -#ifdef USE_PCRE_JIT regex->extra = pcre_study(regex->reg, PCRE_STUDY_JIT_COMPILE, &error); if (!regex->extra && error != NULL) { pcre_free(regex->reg); memprintf(err, "failed to compile regex '%s' (error=%s)", str, error); return 0; } -#else - regex->extra = NULL; -#endif #else int flags = REG_EXTENDED;