Skip to content

Commit 479601e

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 149c9e2 commit 479601e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

builtin/archive.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,16 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
100100
if (output)
101101
create_output_file(output);
102102

103-
if (remote)
104-
return run_remote_archiver(argc, argv, remote, exec, output);
103+
if (remote) {
104+
ret = run_remote_archiver(argc, argv, remote, exec, output);
105+
goto out;
106+
}
105107

106108
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
107109

108110
ret = write_archive(argc, argv, prefix, the_repository, output, 0);
109111

112+
out:
110113
free(output);
111114
return ret;
112115
}

t/t5000-tar-tree.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ commit id embedding:
2525
'
2626

2727
TEST_CREATE_REPO_NO_TEMPLATE=1
28+
TEST_PASSES_SANITIZE_LEAK=true
2829
. ./test-lib.sh
2930

3031
SUBSTFORMAT=%H%n

t/t5003-archive-zip.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
test_description='git archive --format=zip test'
44

55
TEST_CREATE_REPO_NO_TEMPLATE=1
6+
TEST_PASSES_SANITIZE_LEAK=true
67
. ./test-lib.sh
78

89
SUBSTFORMAT=%H%n

0 commit comments

Comments
 (0)