test-tool urlmatch-normalization: fix a memory leak

Fix a memory leak in "test-tool urlmatch-normalization", as a result we can mark the corresponding test as passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 1, 2022 at 12:37 UTC 1c343e5aef0599a7a4816aa7fce5c7c84c10388d
2 files changed +10 -3
t/helper/test-urlmatch-normalization.c
+8 -3
@@ -5,8 +5,9 @@
5 int cmd__urlmatch_normalization(int argc, const char **argv)
6 {
7 const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
8 - char *url1, *url2;
8 + char *url1 = NULL, *url2 = NULL;
9 int opt_p = 0, opt_l = 0;
10 + int ret = 0;
11
12 /*
13 * For one url, succeed if url_normalize succeeds on it, fail otherwise.
@@ -39,7 +40,7 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
40 printf("%s\n", url1);
41 if (opt_l)
42 printf("%u\n", (unsigned)info.url_len);
42 - return 0;
43 + goto cleanup;
44 }
45
46 if (opt_p || opt_l)
@@ -47,5 +48,9 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
48
49 url1 = url_normalize(argv[1], NULL);
50 url2 = url_normalize(argv[2], NULL);
50 - return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
51 + ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
52 +cleanup:
53 + free(url1);
54 + free(url2);
55 + return ret;
56 }
t/t0110-urlmatch-normalization.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='urlmatch URL normalization'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # The base name of the test url files