Skip to content

Commit 1c343e5

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9afa46d commit 1c343e5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

t/helper/test-urlmatch-normalization.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
int cmd__urlmatch_normalization(int argc, const char **argv)
66
{
77
const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
8-
char *url1, *url2;
8+
char *url1 = NULL, *url2 = NULL;
99
int opt_p = 0, opt_l = 0;
10+
int ret = 0;
1011

1112
/*
1213
* For one url, succeed if url_normalize succeeds on it, fail otherwise.
@@ -39,13 +40,17 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
3940
printf("%s\n", url1);
4041
if (opt_l)
4142
printf("%u\n", (unsigned)info.url_len);
42-
return 0;
43+
goto cleanup;
4344
}
4445

4546
if (opt_p || opt_l)
4647
die("%s", usage);
4748

4849
url1 = url_normalize(argv[1], NULL);
4950
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;
5156
}

t/t0110-urlmatch-normalization.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='urlmatch URL normalization'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
# The base name of the test url files

0 commit comments

Comments
 (0)