]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shallow: free grafts when unregistering them
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Sep 2024 10:09:15 +0000 (12:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2024 15:49:12 +0000 (08:49 -0700)
When removing a graft via `unregister_shallow()` we remove it from the
grafts array, but do not free the structure. Fix this to plug the leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
shallow.c
t/t5537-fetch-shallow.sh

index a10cf9e9d5d4b43073174b13a653e49b825c5398..7e0ee96ead99f3ecc23f32344acc1c43ca8e2faa 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -51,10 +51,12 @@ int unregister_shallow(const struct object_id *oid)
        int pos = commit_graft_pos(the_repository, oid);
        if (pos < 0)
                return -1;
-       if (pos + 1 < the_repository->parsed_objects->grafts_nr)
+       if (pos + 1 < the_repository->parsed_objects->grafts_nr) {
+               free(the_repository->parsed_objects->grafts[pos]);
                MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
                           the_repository->parsed_objects->grafts + pos + 1,
                           the_repository->parsed_objects->grafts_nr - pos - 1);
+       }
        the_repository->parsed_objects->grafts_nr--;
        return 0;
 }
index 37f7547a4cadb22929d7f88d9d8e11e5059b9d32..cae4d400f32e8becf40c51bc074dbe972ba27c95 100755 (executable)
@@ -5,6 +5,7 @@ test_description='fetch/clone from a shallow clone'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 commit() {