Skip to content

Commit e287a5b

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

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

t/helper/test-path-utils.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ int cmd__path_utils(int argc, const char **argv)
296296
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
297297
char *buf = xmallocz(strlen(argv[2]));
298298
int rv = normalize_path_copy(buf, argv[2]);
299-
if (rv)
300-
buf = "++failed++";
301-
puts(buf);
299+
puts(rv ? "++failed++" : buf);
300+
free(buf);
302301
return 0;
303302
}
304303

@@ -356,7 +355,10 @@ int cmd__path_utils(int argc, const char **argv)
356355
int nongit_ok;
357356
setup_git_directory_gently(&nongit_ok);
358357
while (argc > 3) {
359-
puts(prefix_path(prefix, prefix_len, argv[3]));
358+
char *pfx = prefix_path(prefix, prefix_len, argv[3]);
359+
360+
puts(pfx);
361+
free(pfx);
360362
argc--;
361363
argv++;
362364
}
@@ -366,6 +368,7 @@ int cmd__path_utils(int argc, const char **argv)
366368
if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) {
367369
char *prefix = strip_path_suffix(argv[2], argv[3]);
368370
printf("%s\n", prefix ? prefix : "(null)");
371+
free(prefix);
369372
return 0;
370373
}
371374

t/t0060-path-utils.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
test_description='Test various path utilities'
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
norm_path() {

0 commit comments

Comments
 (0)