]> git.ipfire.org Git - thirdparty/git.git/commit
commit: discard partial cache before (re-)reading it
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 8 Nov 2022 18:17:39 +0000 (19:17 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Nov 2022 03:32:48 +0000 (12:32 +0900)
commit03267e8656c23cf1e2d1df8204d4cee236fb0077
treea7dd61334bceeadcaf0b48a0529b6ba889afd885
parentab2cf37183eb461f1a5176a4d58650e7c8f642eb
commit: discard partial cache before (re-)reading it

The read_cache() in prepare_to_commit() would end up clobbering the
pointer we had for a previously populated "the_index.cache_tree" in
the very common case of "git commit" stressed by e.g. the tests being
changed here.

We'd populate "the_index.cache_tree" by calling
"update_main_cache_tree" in prepare_index(), but would not end up with
a "fully prepared" index. What constitutes an existing index is
clearly overly fuzzy, here we'll check "active_nr" (aka
"the_index.cache_nr"), but our "the_index.cache_tree" might have been
malloc()'d already.

Thus the code added in 11c8a74a64a (commit: write cache-tree data when
writing index anyway, 2011-12-06) would end up allocating the
"cache_tree", and would interact here with code added in
7168624c353 (Do not generate full commit log message if it is not
going to be used, 2007-11-28). The result was a very common memory
leak.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
19 files changed:
builtin/commit.c
t/t0068-for-each-repo.sh
t/t0070-fundamental.sh
t/t1404-update-ref-errors.sh
t/t1409-avoid-packing-refs.sh
t/t1413-reflog-detach.sh
t/t1501-work-tree.sh
t/t2025-checkout-no-overlay.sh
t/t3009-ls-files-others-nonsubmodule.sh
t/t3010-ls-files-killed-modified.sh
t/t4045-diff-relative.sh
t/t4111-apply-subdir.sh
t/t4135-apply-weird-filenames.sh
t/t4213-log-tabexpand.sh
t/t5618-alternate-refs.sh
t/t6301-for-each-ref-errors.sh
t/t7520-ignored-hook-warning.sh
t/t7614-merge-signoff.sh
t/t9003-help-autocorrect.sh