split-index: fix memory leak in move_cache_to_base_index()
In `move_cache_to_base_index()` we move the index cache of the main index into the split index, which is used when writing a shared index. But we don't release the old split index base in case we already had a split index before this operation, which can thus leak memory. Plug the leak by releasing the previous base. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1dd7c32daa
commit
a5408d1820
@ -97,7 +97,11 @@ void move_cache_to_base_index(struct index_state *istate)
|
|||||||
mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
|
mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALLOC_ARRAY(si->base, 1);
|
if (si->base)
|
||||||
|
release_index(si->base);
|
||||||
|
else
|
||||||
|
ALLOC_ARRAY(si->base, 1);
|
||||||
|
|
||||||
index_state_init(si->base, istate->repo);
|
index_state_init(si->base, istate->repo);
|
||||||
si->base->version = istate->version;
|
si->base->version = istate->version;
|
||||||
/* zero timestamp disables racy test in ce_write_index() */
|
/* zero timestamp disables racy test in ce_write_index() */
|
||||||
|
@ -5,6 +5,7 @@ test_description='split index mode tests'
|
|||||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
# We need total control of index splitting here
|
# We need total control of index splitting here
|
||||||
|
Reference in New Issue
Block a user