t/helper: fix leaks in "reach" test tool

The "reach" test tool doesn't bother to clean up any of its allocated resources, causing various leaks. Plug them. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 5, 2024 at 07:16 UTC ee3e8c3afa5f432c5232aba80a07b0884d388381
2 files changed +11
t/helper/test-reach.c
+10
@@ -127,10 +127,12 @@ int cmd__reach(int ac, const char **av)
127 exit(128);
128 printf("%s(A,X):\n", av[1]);
129 print_sorted_commit_ids(list);
130 + free_commit_list(list);
131 } else if (!strcmp(av[1], "reduce_heads")) {
132 struct commit_list *list = reduce_heads(X);
133 printf("%s(X):\n", av[1]);
134 print_sorted_commit_ids(list);
135 + free_commit_list(list);
136 } else if (!strcmp(av[1], "can_all_from_reach")) {
137 printf("%s(X,Y):%d\n", av[1], can_all_from_reach(X, Y, 1));
138 } else if (!strcmp(av[1], "can_all_from_reach_with_flag")) {
@@ -153,6 +155,7 @@ int cmd__reach(int ac, const char **av)
155 filter.with_commit_tag_algo = 0;
156
157 printf("%s(_,A,X,_):%d\n", av[1], commit_contains(&filter, A, X, &cache));
158 + clear_contains_cache(&cache);
159 } else if (!strcmp(av[1], "get_reachable_subset")) {
160 const int reachable_flag = 1;
161 int i, count = 0;
@@ -176,7 +179,14 @@ int cmd__reach(int ac, const char **av)
179 die(_("too many commits marked reachable"));
180
181 print_sorted_commit_ids(list);
182 + free_commit_list(list);
183 }
184
185 + object_array_clear(&X_obj);
186 + strbuf_release(&buf);
187 + free_commit_list(X);
188 + free_commit_list(Y);
189 + free(X_array);
190 + free(Y_array);
191 return 0;
192 }
t/t6600-test-reach.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='basic commit reachability tests'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # Construct a grid-like commit graph with points (x,y)