Skip to content

Commit aa9ef61

Browse files
pks-tgitster
authored andcommitted
object-file: fix memory leak when reading corrupted headers
When reading corrupt object headers in `read_loose_object()`, we bail out immediately. This causes a memory leak though because we would have already initialized the zstream in `unpack_loose_header()`, and it is the callers responsibility to finish the zstream even on error. While this feels weird, other callsites do it correctly already. Fix this leak by ending the zstream even on errors. We may want to revisit this interface in the future such that the callee handles this for us already when there was an error. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce15f9e commit aa9ef61

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

object-file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,7 @@ int read_loose_object(const char *path,
29542954
if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
29552955
NULL) != ULHR_OK) {
29562956
error(_("unable to unpack header of %s"), path);
2957+
git_inflate_end(&stream);
29572958
goto out;
29582959
}
29592960

t/t1450-fsck.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ test_description='git fsck random collection of tests
66
* (main) A
77
'
88

9+
TEST_PASSES_SANITIZE_LEAK=true
910
. ./test-lib.sh
1011

1112
test_expect_success setup '

0 commit comments

Comments
 (0)