git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 07/10] grep/pcre2: use pcre2_maketables_free() function

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 10, 2021, 10:43 UTC
Message-ID
<nycvar.QRO.7.76.6.2102101142020.29765@tvgsbejvaqbjf.bet>
In-Reply-To
<20210204210556.25242-8-avarab@gmail.com>
Hi Ævar,
On Thu, 4 Feb 2021, Ævar Arnfjörð Bjarmason wrote:
Show 9 quoted lines
> Make use of the pcre2_maketables_free() function to free the memory
> allocated by pcre2_maketables(). At first sight it's strange that
> 10da030ab75 (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 513f2b0bbd4 (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.

Git for Windows still uses v10.33. Thanks for the prod, I will update the library.

Ciao, Dscho

Show 47 quoted lines
>
> 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 <avarab@gmail.com>
> ---
>  grep.c | 4 ++++
>  grep.h | 3 +++
>  2 files changed, 7 insertions(+)
>
> diff --git a/grep.c b/grep.c
> index e58044474d..c63dbff4b2 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -490,7 +490,11 @@ static void free_pcre2_pattern(struct grep_pat *p)
>  	pcre2_compile_context_free(p->pcre2_compile_context);
>  	pcre2_code_free(p->pcre2_pattern);
>  	pcre2_match_data_free(p->pcre2_match_data);
> +#ifdef GIT_PCRE2_VERSION_10_34_OR_HIGHER
> +	pcre2_maketables_free(pcre2_global_context, p->pcre2_tables);
> +#else
>  	free((void *)p->pcre2_tables);
> +#endif
>  }
>  #else /* !USE_LIBPCRE2 */
>  static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
> diff --git a/grep.h b/grep.h
> index 54e52042cb..64666e9204 100644
> --- a/grep.h
> +++ b/grep.h
> @@ -7,6 +7,9 @@
>  #if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11
>  #define GIT_PCRE2_VERSION_10_36_OR_HIGHER
>  #endif
> +#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 34) || PCRE2_MAJOR >= 11
> +#define GIT_PCRE2_VERSION_10_34_OR_HIGHER
> +#endif
>  #else
>  typedef int pcre2_code;
>  typedef int pcre2_match_data;
> --
> 2.30.0.284.gd98b1dd5eaa7
>
>
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 37 of 42 in “Revive 'pcre2-chartables-leakfix'”
  1. 0/3 Revive 'pcre2-chartables-leakfix'Johannes Schindelin via GitGitGadget, Oct 16, 2019
  2. 2/3 grep: make PCRE2 aware of custom allocatorCarlo Marcelo Arenas Belón via GitGitGadget, Oct 16, 2019
  3. 1/3 grep: make PCRE1 aware of custom allocatorCarlo Marcelo Arenas Belón via GitGitGadget, Oct 16, 2019
  4. 3/3 grep: avoid leak of chartables in PCRE2Johannes Schindelin via GitGitGadget, Oct 16, 2019
  5. 0/3 Revive 'pcre2-chartables-leakfix'Johannes Schindelin via GitGitGadget, Oct 16, 2019
  6. 1/3 grep: make PCRE1 aware of custom allocatorCarlo Marcelo Arenas Belón via GitGitGadget, Oct 16, 2019
  7. 2/3 grep: make PCRE2 aware of custom allocatorCarlo Marcelo Arenas Belón via GitGitGadget, Oct 16, 2019
  8. Junio C HamanoOct 18, 2019
  9. 00/10 grep/pcre2: memory allocation fixesÆvar Arnfjörð Bjarmason, Feb 4, 2021
  10. Junio C HamanoFeb 10, 2021
  11. 00/10 grep/pcre2: memory allocation fixesÆvar Arnfjörð Bjarmason, Feb 18, 2021
  12. Junio C HamanoMar 4, 2021
  13. 03/10 grep/pcre2: correct reference to grep_init() in commentÆvar Arnfjörð Bjarmason, Feb 18, 2021
  14. 04/10 grep/pcre2: prepare to add debugging to pcre2_malloc()Ævar Arnfjörð Bjarmason, Feb 18, 2021
  15. 02/10 grep/pcre2: drop needless assignment to NULLÆvar Arnfjörð Bjarmason, Feb 18, 2021
  16. 01/10 grep/pcre2: drop needless assignment + assert() on opt->pcre2Ævar Arnfjörð Bjarmason, Feb 18, 2021
  17. 05/10 grep/pcre2: add GREP_PCRE2_DEBUG_MALLOC debug modeÆvar Arnfjörð Bjarmason, Feb 18, 2021
  18. 06/10 grep/pcre2: use compile-time PCREv2 version testÆvar Arnfjörð Bjarmason, Feb 18, 2021
  19. Junio C HamanoMar 4, 2021
  20. 07/10 grep/pcre2: use pcre2_maketables_free() functionÆvar Arnfjörð Bjarmason, Feb 18, 2021
  21. 08/10 grep/pcre2: actually make pcre2 use custom allocatorÆvar Arnfjörð Bjarmason, Feb 18, 2021
  22. Junio C HamanoMar 4, 2021
  23. 10/10 grep/pcre2: move definitions of pcre2_{malloc,free}Ævar Arnfjörð Bjarmason, Feb 18, 2021
  24. Junio C HamanoMar 4, 2021
  25. 09/10 grep/pcre2: move back to thread-only PCREv2 structuresÆvar Arnfjörð Bjarmason, Feb 18, 2021
  26. Junio C HamanoMar 4, 2021
  27. 01/10 grep/pcre2: drop needless assignment + assert() on opt->pcre2Ævar Arnfjörð Bjarmason, Feb 4, 2021
  28. 02/10 grep/pcre2: drop needless assignment to NULLÆvar Arnfjörð Bjarmason, Feb 4, 2021
  29. 03/10 grep/pcre2: correct reference to grep_init() in commentÆvar Arnfjörð Bjarmason, Feb 4, 2021
  30. 04/10 grep/pcre2: prepare to add debugging to pcre2_malloc()Ævar Arnfjörð Bjarmason, Feb 4, 2021
  31. 05/10 grep/pcre2: add GREP_PCRE2_DEBUG_MALLOC debug modeÆvar Arnfjörð Bjarmason, Feb 4, 2021
  32. Johannes SchindelinFeb 10, 2021
  33. 06/10 grep/pcre2: use compile-time PCREv2 version testÆvar Arnfjörð Bjarmason, Feb 4, 2021
  34. 08/10 grep/pcre2: actually make pcre2 use custom allocatorÆvar Arnfjörð Bjarmason, Feb 4, 2021
  35. Johannes SchindelinFeb 10, 2021
  36. 07/10 grep/pcre2: use pcre2_maketables_free() functionÆvar Arnfjörð Bjarmason, Feb 4, 2021
  37. Johannes SchindelinFeb 10, 2021
  38. Junio C HamanoMar 4, 2021
  39. 09/10 grep/pcre2: move back to thread-only PCREv2 structuresÆvar Arnfjörð Bjarmason, Feb 4, 2021
  40. 10/10 grep/pcre2: move definitions of pcre2_{malloc,free}Ævar Arnfjörð Bjarmason, Feb 4, 2021
  41. Johannes SchindelinFeb 10, 2021
  42. 3/3 grep: avoid leak of chartables in PCRE2Carlo Marcelo Arenas Belón via GitGitGadget, Oct 16, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.