threads / patch / 60560

patchcolumn: release strbuf and string_list after use

Subject: [PATCH] column: release strbuf and string_list after use

## tl;dr

2 messages between Nov 26, 2023 and Nov 27, 2023. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Nov 26, 2023, 11:57 UTC · lore

Releasing strbuf and string_list just before exiting is not strictly necessary, but it gets rid of false positives reported by leak checkers, which can then be more easily used to show that the column-printing machinery behind print_columns() are free of leaks.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/column.c  | 2 ++
 t/t9002-column.sh | 1 +
 2 files changed, 3 insertions(+)
Show changes to 2 files +3 −1

builtin/column.c, t/t9002-column.sh

diff --git a/builtin/column.c b/builtin/column.c
index a83be8bc99..e80218f81f 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -56,5 +56,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
 		string_list_append(&list, sb.buf);

 	print_columns(&list, colopts, &copts);
+	strbuf_release(&sb);
+	string_list_clear(&list, 0);
 	return 0;
 }
diff --git a/t/t9002-column.sh b/t/t9002-column.sh
index 6d3dbde3fe..348cc40658 100755
--- a/t/t9002-column.sh
+++ b/t/t9002-column.sh
@@ -1,6 +1,7 @@
 #!/bin/sh

 test_description='git column'
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh

 test_expect_success 'setup' '
--
2.43.0
Junio C Hamano· Nov 27, 2023, 12:04 UTC · re: René Scharfe · lore

Re: [PATCH] column: release strbuf and string_list after use

René Scharfe <l.s.r@web.de> writes:
> Releasing strbuf and string_list just before exiting is not strictly
> necessary, but it gets rid of false positives reported by leak checkers,
> which can then be more easily used to show that the column-printing
> machinery behind print_columns() are free of leaks.
Thanks for being careful.  Will queue.

← back to recent threads