Git development
 help / color / mirror / Atom feed
* [PATCH] test-mergesort: plug memory leaks in sort_stdin()
@ 2026-10-07  3:42 Muhammed Dilshad A
  2026-10-07  6:13 ` Patrick Steinhardt
  2026-10-07 13:50 ` [PATCH v2 0/3] mergesort: move tests to Clar and retire the helper Muhammed Dilshad A
  0 siblings, 2 replies; 16+ messages in thread
From: Muhammed Dilshad A @ 2026-10-07  3:42 UTC (permalink / raw)
  To: git; +Cc: Muhammed Dilshad A

The sort_stdin() helper allocates an input buffer and a memory pool for
the list of lines, but returns without releasing either. Discard the
pool and release the strbuf after printing the sorted lines.

Add a test for the sort subcommand to t0071. The existing test only
exercises the test subcommand, leaving these leaks undetected by the
regular leak-sanitized test suite.

Signed-off-by: Muhammed Dilshad A <dilsheddilu123@gmail.com>
---
 t/helper/test-mergesort.c | 2 ++
 t/t0071-sort.sh           | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/t/helper/test-mergesort.c b/t/helper/test-mergesort.c
index 791e128793..3b8c428b14 100644
--- a/t/helper/test-mergesort.c
+++ b/t/helper/test-mergesort.c
@@ -61,6 +61,8 @@ static int sort_stdin(void)
 		puts(lines->text);
 		lines = lines->next;
 	}
+	mem_pool_discard(&lines_pool, 0);
+	strbuf_release(&sb);
 	return 0;
 }
 
diff --git a/t/t0071-sort.sh b/t/t0071-sort.sh
index 2236a7e956..97890da29f 100755
--- a/t/t0071-sort.sh
+++ b/t/t0071-sort.sh
@@ -8,4 +8,11 @@ test_expect_success 'DEFINE_LIST_SORT_DEBUG' '
 	test-tool mergesort test
 '
 
+test_expect_success 'sort stdin' '
+	printf "%s\n" c a b >input &&
+	printf "%s\n" a b c >expect &&
+	test-tool mergesort sort <input >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-10-09 15:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-07  3:42 [PATCH] test-mergesort: plug memory leaks in sort_stdin() Muhammed Dilshad A
2026-10-07  6:13 ` Patrick Steinhardt
2026-10-07 17:27   ` Junio C Hamano
2026-10-07 13:50 ` [PATCH v2 0/3] mergesort: move tests to Clar and retire the helper Muhammed Dilshad A
2026-10-07 13:50   ` [PATCH v2 1/3] test-mergesort: plug memory leaks in sort_stdin() Muhammed Dilshad A
2026-10-07 13:50   ` [PATCH v2 2/3] mergesort: move sorting tests to the unit-test framework Muhammed Dilshad A
2026-10-09 11:52     ` Patrick Steinhardt
2026-10-09 13:55       ` Muhammed Dilshad A
2026-10-07 13:50   ` [PATCH v2 3/3] t: retire the sorting benchmark and mergesort helper Muhammed Dilshad A
2026-10-09 11:52   ` [PATCH v2 0/3] mergesort: move tests to Clar and retire the helper Patrick Steinhardt
2026-10-09 13:56     ` Muhammed Dilshad A
2026-10-09 15:08   ` [PATCH v3 0/4] mergesort: move tests to Clar and remove " Muhammed Dilshad A
2026-10-09 15:08     ` [PATCH v3 1/4] mergesort: move sorting tests to Clar Muhammed Dilshad A
2026-10-09 15:08     ` [PATCH v3 2/4] mergesort: simplify the unit tests Muhammed Dilshad A
2026-10-09 15:08     ` [PATCH v3 3/4] mergesort: cover empty and small lists Muhammed Dilshad A
2026-10-09 15:08     ` [PATCH v3 4/4] t: retire the sorting benchmark and mergesort helper Muhammed Dilshad A

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox