Skip to content

Commit a5408d1

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1dd7c32 commit a5408d1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

split-index.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ void move_cache_to_base_index(struct index_state *istate)
9797
mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
9898
}
9999

100-
ALLOC_ARRAY(si->base, 1);
100+
if (si->base)
101+
release_index(si->base);
102+
else
103+
ALLOC_ARRAY(si->base, 1);
104+
101105
index_state_init(si->base, istate->repo);
102106
si->base->version = istate->version;
103107
/* zero timestamp disables racy test in ce_write_index() */

t/t1700-split-index.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='split index mode tests'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
# We need total control of index splitting here

0 commit comments

Comments
 (0)