From edd24460814edba9d8e482e34ec524668769b6ea Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 7 Jul 2024 16:33:40 +0100 Subject: [PATCH] Fix a memory leak in the regex_pcre2 module. --- src/modules/extra/m_regex_pcre2.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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); } };