mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
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 in11c8a74a64
(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 in7168624c35
(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>
This commit is contained in:
parent
982d2531c9
commit
407b94280f
19 changed files with 29 additions and 2 deletions
|
@ -987,8 +987,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
|||
struct object_id oid;
|
||||
const char *parent = "HEAD";
|
||||
|
||||
if (!active_nr && read_cache() < 0)
|
||||
die(_("Cannot read index"));
|
||||
if (!active_nr) {
|
||||
discard_cache();
|
||||
if (read_cache() < 0)
|
||||
die(_("Cannot read index"));
|
||||
}
|
||||
|
||||
if (amend)
|
||||
parent = "HEAD^1";
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='git for-each-repo builtin'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'run based on configured value' '
|
||||
|
|
|
@ -6,6 +6,7 @@ test_description='check that the most basic functions work
|
|||
Verify wrappers and compatibility functions.
|
||||
'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'character classes (isspace, isalpha etc.)' '
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='Test git update-ref error handling'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
# Create some references, perhaps run pack-refs --all, then try to
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='avoid rewriting packed-refs unnecessarily'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
# Add an identifying mark to the packed-refs file header line. This
|
||||
|
|
|
@ -4,6 +4,7 @@ test_description='Test reflog interaction with detached HEAD'
|
|||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
reset_state () {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='test separate work tree'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='checkout --no-overlay <tree-ish> -- <pathspec>'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
|
|
@ -18,6 +18,7 @@ This test runs git ls-files --others with the following working tree:
|
|||
git repository with a commit and an untracked file
|
||||
'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup: directories' '
|
||||
|
|
|
@ -41,6 +41,8 @@ Also for modification test, the cache and working tree have:
|
|||
We should report path0, path1, path2/file2, path3/file3, path7 and path8
|
||||
modified without reporting path9 and path10. submod1 is also modified.
|
||||
'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'git update-index --add to add various paths.' '
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='diff --relative tests'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='patching from inconvenient places'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='git apply with weird postimage filenames'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='log/show --expand-tabs'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
HT=" "
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='test handling of --alternate-refs traversal'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
# Avoid test_commit because we want a specific and known set of refs:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='for-each-ref errors for broken refs'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
ZEROS=$ZERO_OID
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
test_description='ignored hook warning'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success setup '
|
||||
|
|
|
@ -8,6 +8,7 @@ This test runs git merge --signoff and makes sure that it works.
|
|||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
# Setup test files
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='help.autocorrect finding a match'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
|
Loading…
Reference in a new issue