]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/archive: fix leaking `OPT_FILENAME()` value
authorPatrick Steinhardt <ps@pks.im>
Thu, 22 Aug 2024 09:17:30 +0000 (11:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2024 16:18:04 +0000 (09:18 -0700)
The "--output" switch is an `OPT_FILENAME()` option, which allocates
memory when specified by the user. But while we free the string when
executed without the "--remote" switch, we don't otherwise because we
return via a separate exit path that doesn't know to free it.

Fix this by creating a common exit path.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/archive.c
t/t5000-tar-tree.sh
t/t5003-archive-zip.sh

index b50981504f3bcf012f0f3d612c0d6927400e4871..63f02990d112d7509fd20eaa277988cb44a8e023 100644 (file)
@@ -100,13 +100,16 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
        if (output)
                create_output_file(output);
 
-       if (remote)
-               return run_remote_archiver(argc, argv, remote, exec, output);
+       if (remote) {
+               ret = run_remote_archiver(argc, argv, remote, exec, output);
+               goto out;
+       }
 
        setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
 
        ret = write_archive(argc, argv, prefix, the_repository, output, 0);
 
+out:
        free(output);
        return ret;
 }
index 72b8d0ff02e34be0606747c850b0815be31196d4..7abba8a4b20caad28414e8169688f587cf7df837 100755 (executable)
@@ -25,6 +25,7 @@ commit id embedding:
 '
 
 TEST_CREATE_REPO_NO_TEMPLATE=1
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 SUBSTFORMAT=%H%n
index 961c6aac2561354f6ad57270c1362fe73c850924..01f591c99b962fced8c5b6e0b1538ad847f814d7 100755 (executable)
@@ -3,6 +3,7 @@
 test_description='git archive --format=zip test'
 
 TEST_CREATE_REPO_NO_TEMPLATE=1
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 SUBSTFORMAT=%H%n