diff --git a/src/modules/extra/m_regex_pcre2.cpp b/src/modules/extra/m_regex_pcre2.cpp index 35bc39b0f..5b5fa4995 100644 --- a/src/modules/extra/m_regex_pcre2.cpp +++ b/src/modules/extra/m_regex_pcre2.cpp @@ -80,7 +80,10 @@ public: pcre2_match_data* data = pcre2_match_data_create_from_pattern(regex, nullptr); int result = pcre2_match(regex, reinterpret_cast(text.c_str()), text.length(), 0, 0, data, nullptr); if (result < 0) + { + pcre2_match_data_free(data); return std::nullopt; + } PCRE2_SIZE* ovector = pcre2_get_ovector_pointer(data); @@ -117,6 +120,7 @@ public: } } + pcre2_match_data_free(data); return Regex::MatchCollection(captures, namedcaptures); } };