>From 75cd3b441c216134c9708e3e4b67720a4cdb096b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Mon, 15 Nov 2021 14:19:15 -0800 Subject: [PATCH] pcre: only make tables when needed and make them always reachable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When doing a match in non utf mode, chartables that reflect the corresponding attributes that the locale define are needed, and therefore that information is passed through a compile context. Before ad6e5cb (grep: fix minor -P memory leak, 2021-11-14), the table will leak together with the compile context on the hopes it will be eventually free if a cleanup callback is even invented, but now is not only leaking but unreachable, so at least make it reachable again and while at it, make sure it is only created when needed. Signed-off-by: Carlo Marcelo Arenas Belón --- src/pcresearch.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pcresearch.c b/src/pcresearch.c index c12c674..1f322f4 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -41,6 +41,9 @@ struct pcre_comp /* Compiled internal form of a Perl regular expression. */ pcre2_code *cre; + /* Charset tables. */ + const uint8_t *tables; + /* Match context and data block. */ pcre2_match_context *mcontext; pcre2_match_data *data; @@ -193,7 +196,14 @@ Pcompile (char *pattern, idx_t size, reg_syntax_t ignored, bool exact) size = re_size; } - pcre2_set_character_tables (ccontext, pcre2_maketables (gcontext)); + if (! localeinfo.using_utf8) + { + pc->tables = pcre2_maketables (gcontext); + pcre2_set_character_tables (ccontext, pc->tables); + } + else + pc->tables = NULL; + pc->cre = pcre2_compile ((PCRE2_SPTR) pattern, size, flags, &ec, &e, ccontext); if (!pc->cre) -- 2.34.0.352.g07dee3c5e1