]> git.ipfire.org Git - thirdparty/git.git/commit
read-cache: fix leaking hashfile when writing index fails
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:52:06 +0000 (08:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:07:58 +0000 (10:07 -0700)
commitd1c53f6703f34eeb3442070016db6e4d1f5676d2
tree991324e01dcfd102400dd4f8bd017a7189b9c9a5
parentc81dcf630cec64d0042f08f7210300671ed5b926
read-cache: fix leaking hashfile when writing index fails

In `do_write_index()`, we use a `struct hashfile` to write the index
with a trailer hash. In case the write fails though, we never clean up
the allocated `hashfile` state and thus leak memory.

Refactor the code to have a common exit path where we can free this and
other allocated memory. While at it, refactor our use of `strbuf`s such
that we reuse the same buffer to avoid some unneeded allocations.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c
t/t1601-index-bogus.sh
t/t2107-update-index-basic.sh
t/t7008-filter-branch-null-sha1.sh