Skip to content

Commit 49752f3

Browse files
avargitster
authored andcommitted
upload-pack: fix a memory leak in create_pack_file()
Fix a memory leak that's been reported by some versions of "gcc" since "output_state" became malloc'd in 55a9651 (upload-pack.c: increase output buffer size, 2021-12-14). In e75d2f7 (revisions API: have release_revisions() release "filter", 2022-04-13) it was correctly marked as leak-free, the only path through this function that doesn't reach the free(output_state) is if we "goto fail", and that will invoke "die()". Such leaks are not included with SANITIZE=leak (but e.g. valgrind will still report them), but under some gcc optimization (I have not been able to reproduce it with "clang") we'll report a leak here anyway. E.g. gcc v12 with "-O2" and above will trigger it, but not clang v13 with any "-On". The GitHub CI would also run into this leak if the "linux-leaks" job was made to run with "GIT_TEST_SANITIZE_LEAK_LOG=true". See [1] for a past case where gcc had similar trouble analyzing leaks involving a die() invocation in the function. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e55ad48 commit 49752f3

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

t/t1060-object-corruption.sh

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

33
test_description='see how we handle various forms of corruption'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
# convert "1234abcd" to ".git/objects/12/34abcd"

upload-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ static void create_pack_file(struct upload_pack_data *pack_data,
455455
return;
456456

457457
fail:
458+
free(output_state);
458459
send_client_data(3, abort_msg, sizeof(abort_msg),
459460
pack_data->use_sideband);
460461
die("git upload-pack: %s", abort_msg);

0 commit comments

Comments
 (0)