Skip to content

Commit b76bf27

Browse files
avargitster
authored andcommitted
grep/pcre2: use pcre2_maketables_free() function
Make use of the pcre2_maketables_free() function to free the memory allocated by pcre2_maketables(). At first sight it's strange that 10da030 (grep: avoid leak of chartables in PCRE2, 2019-10-16) which added the free() call here doesn't make use of the pcre2_free() the author introduced in the preceding commit in 513f2b0 (grep: make PCRE2 aware of custom allocator, 2019-10-16). The reason is that at the time the function didn't exist. It was first introduced in PCREv2 version 10.34, released on 2019-11-21. Let's make use of it behind a macro. I don't think this matters for anything to do with custom allocators, but it makes our use of PCREv2 more discoverable. At some distant point in the future we'll be able to drop the version guard, as nobody will be running a version older than 10.34. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 797c359 commit b76bf27

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

grep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,11 @@ static void free_pcre2_pattern(struct grep_pat *p)
490490
pcre2_compile_context_free(p->pcre2_compile_context);
491491
pcre2_code_free(p->pcre2_pattern);
492492
pcre2_match_data_free(p->pcre2_match_data);
493+
#ifdef GIT_PCRE2_VERSION_10_34_OR_HIGHER
494+
pcre2_maketables_free(pcre2_global_context, p->pcre2_tables);
495+
#else
493496
free((void *)p->pcre2_tables);
497+
#endif
494498
}
495499
#else /* !USE_LIBPCRE2 */
496500
static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)

grep.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11
88
#define GIT_PCRE2_VERSION_10_36_OR_HIGHER
99
#endif
10+
#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 34) || PCRE2_MAJOR >= 11
11+
#define GIT_PCRE2_VERSION_10_34_OR_HIGHER
12+
#endif
1013
#else
1114
typedef int pcre2_code;
1215
typedef int pcre2_match_data;

0 commit comments

Comments
 (0)