]> git.ipfire.org Git - thirdparty/git.git/commit
unpack-trees: clear index when not propagating it
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:52:39 +0000 (08:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:08:00 +0000 (10:08 -0700)
commit4dfd4f1dfe0d3ddbc22392ad7fc124b4820542dd
treefdddf51eb60e603f2c94aaa0bb3484b40cc563e7
parent2f07d228c3a1c623526ddf38e609dc45c98fb22e
unpack-trees: clear index when not propagating it

When provided a pointer to a destination index, then `unpack_trees()`
will end up copying its `o->internal.result` index into the provided
pointer. In those cases it is thus not necessary to free the index, as
we have transferred ownership of it.

There are cases though where we do not end up transferring ownership of
the memory, but `clear_unpack_trees_porcelain()` will never discard the
index in that case and thus cause a memory leak. And right now it cannot
do so in the first place because we have no indicator of whether we did
or didn't transfer ownership of the index.

Adapt the code to zero out the index in case we transfer its ownership.
Like this, we can now unconditionally discard the index when being asked
to clear the `unpack_trees_options`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3705-add-sparse-checkout.sh
unpack-trees.c