]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-tool path-utils: fix a memory leak
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 1 Jul 2022 10:37:33 +0000 (12:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2022 20:38:49 +0000 (13:38 -0700)
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>
t/helper/test-path-utils.c
t/t0060-path-utils.sh

index 229ed416b0e67867331bfd75fe376834766f7da5..d20e1b7a18d613a97b00e29fa491dc7e1654b21a 100644 (file)
@@ -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;
        }
 
index aa35350b6f396f562463a16ffcba364ab94ed5d5..1f2007e62b753c39992f681a711e4439e6577e3b 100755 (executable)
@@ -5,6 +5,7 @@
 
 test_description='Test various path utilities'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 norm_path() {