shallow: free grafts when unregistering them

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>

Patrick Steinhardt committed Sep 5, 2024 at 12:09 UTC 14c0ea0f6f7a0898214d8fa822a2392ef3a00f53
2 files changed +4 -1
shallow.c
+3 -1
@@ -51,10 +51,12 @@ int unregister_shallow(const struct object_id *oid)
51 int pos = commit_graft_pos(the_repository, oid);
52 if (pos < 0)
53 return -1;
54 - if (pos + 1 < the_repository->parsed_objects->grafts_nr)
54 + if (pos + 1 < the_repository->parsed_objects->grafts_nr) {
55 + free(the_repository->parsed_objects->grafts[pos]);
56 MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
57 the_repository->parsed_objects->grafts + pos + 1,
58 the_repository->parsed_objects->grafts_nr - pos - 1);
59 + }
60 the_repository->parsed_objects->grafts_nr--;
61 return 0;
62 }
t/t5537-fetch-shallow.sh
+1
@@ -5,6 +5,7 @@ test_description='fetch/clone from a shallow clone'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 commit() {