aboutsummaryrefslogtreecommitdiffstats
path: root/t/helper/test-path-utils.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-07-01 12:37:33 +0200
committerJunio C Hamano <gitster@pobox.com>2022-07-01 13:38:49 -0700
commite287a5b0a434e05de39ede507e5b3fc24f67cbb0 (patch)
tree0ecf887404c2c0314f87aca4a6c7c0f7a660baf2 /t/helper/test-path-utils.c
parent330ca8501b6b4cb7afec20dc0b9513542118e9de (diff)
downloadgit-e287a5b0a434e05de39ede507e5b3fc24f67cbb0.tar.gz
test-tool path-utils: fix a memory leak
Fix a memory leak in "test-tool path-utils", 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>
Diffstat (limited to 't/helper/test-path-utils.c')
-rw-r--r--t/helper/test-path-utils.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 229ed416b0..d20e1b7a18 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -296,9 +296,8 @@ int cmd__path_utils(int argc, const char **argv)
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
char *buf = xmallocz(strlen(argv[2]));
int rv = normalize_path_copy(buf, argv[2]);
- if (rv)
- buf = "++failed++";
- puts(buf);
+ puts(rv ? "++failed++" : buf);
+ free(buf);
return 0;
}
@@ -356,7 +355,10 @@ int cmd__path_utils(int argc, const char **argv)
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
while (argc > 3) {
- puts(prefix_path(prefix, prefix_len, argv[3]));
+ char *pfx = prefix_path(prefix, prefix_len, argv[3]);
+
+ puts(pfx);
+ free(pfx);
argc--;
argv++;
}
@@ -366,6 +368,7 @@ int cmd__path_utils(int argc, const char **argv)
if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) {
char *prefix = strip_path_suffix(argv[2], argv[3]);
printf("%s\n", prefix ? prefix : "(null)");
+ free(prefix);
return 0;
}