shallow: fix memory leak when registering shallow roots

When registering shallow roots, we unset the list of parents of the to-be-registered commit if it's already been parsed. This causes us to leak memory though because we never free this list. Fix this. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 6, 2023 at 11:45 UTC 568cc818cc26955eb0b94084d3068caabab1edd7
3 files changed +6 -1
shallow.c
+3 -1
@@ -38,8 +38,10 @@ int register_shallow(struct repository *r, const struct object_id *oid)
38
39 oidcpy(&graft->oid, oid);
40 graft->nr_parent = -1;
41 - if (commit && commit->object.parsed)
41 + if (commit && commit->object.parsed) {
42 + free_commit_list(commit->parents);
43 commit->parents = NULL;
44 + }
45 return register_commit_graft(r, graft, 0);
46 }
47
t/t5311-pack-bitmaps-shallow.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='check bitmap operation with shallow repositories'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # We want to create a situation where the shallow, grafted
t/t5530-upload-pack-error.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='errors in upload-pack'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 D=$(pwd)