From: Junio C Hamano Date: Wed, 23 Oct 2019 05:43:11 +0000 (+0900) Subject: Merge branch 'cb/pcre2-chartables-leakfix' X-Git-Tag: v2.24.0-rc1~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e0ff2d4c7ec338e30ea5e0340cda7f5fe8a187dc;p=thirdparty%2Fgit.git Merge branch 'cb/pcre2-chartables-leakfix' Leakfix. * cb/pcre2-chartables-leakfix: grep: avoid leak of chartables in PCRE2 grep: make PCRE2 aware of custom allocator grep: make PCRE1 aware of custom allocator --- e0ff2d4c7ec338e30ea5e0340cda7f5fe8a187dc diff --cc grep.c index 0bb4cbd3d8,9556d13dc1..b7ae5a442a --- a/grep.c +++ b/grep.c @@@ -470,11 -533,15 +506,15 @@@ static void compile_pcre2_pattern(struc p->pcre2_compile_context = NULL; + /* pcre2_global_context is initialized in append_grep_pattern */ if (opt->ignore_case) { - if (has_non_ascii(p->pattern)) { + if (!opt->ignore_locale && has_non_ascii(p->pattern)) { - character_tables = pcre2_maketables(NULL); + if (!pcre2_global_context) + BUG("pcre2_global_context uninitialized"); + p->pcre2_tables = pcre2_maketables(pcre2_global_context); p->pcre2_compile_context = pcre2_compile_context_create(NULL); - pcre2_set_character_tables(p->pcre2_compile_context, character_tables); + pcre2_set_character_tables(p->pcre2_compile_context, + p->pcre2_tables); } options |= PCRE2_CASELESS; } @@@ -571,6 -643,9 +611,7 @@@ static void free_pcre2_pattern(struct g pcre2_compile_context_free(p->pcre2_compile_context); pcre2_code_free(p->pcre2_pattern); pcre2_match_data_free(p->pcre2_match_data); - pcre2_jit_stack_free(p->pcre2_jit_stack); - pcre2_match_context_free(p->pcre2_match_context); + free((void *)p->pcre2_tables); } #else /* !USE_LIBPCRE2 */ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt) diff --cc grep.h index 05dc1bb98e,533165c21a..811fd274c9 --- a/grep.h +++ b/grep.h @@@ -78,9 -94,12 +78,10 @@@ struct grep_pat pcre2_code *pcre2_pattern; pcre2_match_data *pcre2_match_data; pcre2_compile_context *pcre2_compile_context; - pcre2_match_context *pcre2_match_context; - pcre2_jit_stack *pcre2_jit_stack; + const uint8_t *pcre2_tables; uint32_t pcre2_jit_on; - kwset_t kws; unsigned fixed:1; + unsigned is_fixed:1; unsigned ignore_case:1; unsigned word_regexp:1; };