1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

builtin/archive: fix leaking OPT_FILENAME() value

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>
This commit is contained in:
Patrick Steinhardt 2024-08-22 11:17:30 +02:00 committed by Junio C Hamano
parent 149c9e200c
commit 479601e9f4
3 changed files with 7 additions and 2 deletions

View 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;
}

View file

@ -25,6 +25,7 @@ commit id embedding:
'
TEST_CREATE_REPO_NO_TEMPLATE=1
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
SUBSTFORMAT=%H%n

View file

@ -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