summaryrefslogtreecommitdiffstats
path: root/split-index.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-11-20 14:39:41 +0100
committerJunio C Hamano <gitster@pobox.com>2024-11-21 00:23:43 +0100
commita5408d1820e0ea75612bbd6f6a6c495066e5ffcb (patch)
tree528402c2a6f110402b1ea4324b07e0d363a473ca /split-index.c
parentgit: refactor builtin handling to use a `struct strvec` (diff)
downloadgit-a5408d1820e0ea75612bbd6f6a6c495066e5ffcb.tar.xz
git-a5408d1820e0ea75612bbd6f6a6c495066e5ffcb.zip
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>
Diffstat (limited to 'split-index.c')
-rw-r--r--split-index.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/split-index.c b/split-index.c
index 120c8190b1..cfbc773e6c 100644
--- a/split-index.c
+++ b/split-index.c
@@ -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);
}
- 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);
si->base->version = istate->version;
/* zero timestamp disables racy test in ce_write_index() */