Thread (7 messages) 7 messages, 3 authors, 15h ago

[PATCH] test-mergesort: plug memory leaks in sort_stdin()

flat view
HOTtoday

From: Muhammed Dilshad A <hidden>
Date: 2026-10-07 03:43:31
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help