diff mbox series

[06/25] grep/pcre2: add GREP_PCRE2_DEBUG_MALLOC debug mode

Message ID 20210203032811.14979-7-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series grep: PCREv2 fixes, remove kwset.[ch] | expand

Commit Message

Ævar Arnfjörð Bjarmason Feb. 3, 2021, 3:27 a.m. UTC
Add optional printing of PCREv2 allocations to stderr for a developer
who manually changes the GREP_PCRE2_DEBUG_MALLOC definition to

This will be referenced a subsequent commit, and is generally useful
to manually see what's going on with PCREv2 allocations while working
on that code.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
 grep.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series


diff --git a/grep.c b/grep.c
index f96d86c929..7d262a23d8 100644
--- a/grep.c
+++ b/grep.c
@@ -42,15 +42,25 @@  static struct grep_opt grep_defaults = {
 #ifdef USE_LIBPCRE2
 static pcre2_general_context *pcre2_global_context;
 static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
 	void *pointer = malloc(size);
+	static int count = 1;
+	fprintf(stderr, "PCRE2:%p -> #%02d: alloc(%lu)\n", pointer, count++, size);
 	return pointer;
 static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
+	static int count = 1;
+	if (pointer)
+		fprintf(stderr, "PCRE2:%p -> #%02d: free()\n", pointer, count++);