]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'cb/pcre2-chartables-leakfix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 Oct 2019 05:43:11 +0000 (14:43 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Oct 2019 05:43:11 +0000 (14:43 +0900)
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

1  2 
builtin/grep.c
grep.c
grep.h

diff --cc builtin/grep.c
Simple merge
diff --cc grep.c
index 0bb4cbd3d82ceef5517905a35a7f6820b7fb555a,9556d13dc1dd5f5d7f83e31421846c4f43fbb39d..b7ae5a442a624810471cc4dc8ab84cd1a35c963a
--- 1/grep.c
--- 2/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 05dc1bb98e5e2209a945da6024a757ce02d4d103,533165c21a5229b2ce4a615bdbb34160b821b09c..811fd274c95b0528223fff8d684c5299c10a9967
--- 1/grep.h
--- 2/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;
  };