Skip to content

Commit 14c0ea0

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

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

shallow.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ int unregister_shallow(const struct object_id *oid)
5151
int pos = commit_graft_pos(the_repository, oid);
5252
if (pos < 0)
5353
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]);
5556
MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
5657
the_repository->parsed_objects->grafts + pos + 1,
5758
the_repository->parsed_objects->grafts_nr - pos - 1);
59+
}
5860
the_repository->parsed_objects->grafts_nr--;
5961
return 0;
6062
}

t/t5537-fetch-shallow.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='fetch/clone from a shallow clone'
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
commit() {

0 commit comments

Comments
 (0)