]> git.ipfire.org Git - thirdparty/git.git/commitdiff
split-index: fix memory leak in `move_cache_to_base_index()`
authorPatrick Steinhardt <ps@pks.im>
Wed, 20 Nov 2024 13:39:41 +0000 (14:39 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Nov 2024 23:23:43 +0000 (08:23 +0900)
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>
split-index.c
t/t1700-split-index.sh

index 120c8190b187bc8c6c73630f06f5dd4dc994df30..cfbc773e6cd3b11ea5f47ab92310a56c30f6971c 100644 (file)
@@ -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() */
index ac4a5b2734c0784c2cb8878112a5ead9593860de..2625ac44889a5c9219e9575a9bbc5265d3c419d5 100755 (executable)
@@ -5,6 +5,7 @@ test_description='split index mode tests'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # We need total control of index splitting here