]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shallow: fix memory leak when registering shallow roots
authorPatrick Steinhardt <ps@pks.im>
Mon, 6 Nov 2023 10:45:57 +0000 (11:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Nov 2023 23:51:41 +0000 (08:51 +0900)
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>
shallow.c
t/t5311-pack-bitmaps-shallow.sh
t/t5530-upload-pack-error.sh

index 5413719fd4ef16c130117440c4d4687f9c1c5525..ac728cdd77892dab1c323fc81adaf240d988c6d9 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -38,8 +38,10 @@ int register_shallow(struct repository *r, const struct object_id *oid)
 
        oidcpy(&graft->oid, oid);
        graft->nr_parent = -1;
-       if (commit && commit->object.parsed)
+       if (commit && commit->object.parsed) {
+               free_commit_list(commit->parents);
                commit->parents = NULL;
+       }
        return register_commit_graft(r, graft, 0);
 }
 
index 9dae60f73e3253bbb4b44355535c8cf1ebc58be8..4fe71fe8cd21ddfb0f44821c672585219278bbda 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='check bitmap operation with shallow repositories'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # We want to create a situation where the shallow, grafted
index 7c1460eaa99865306ddfb5254584eba275e17a21..de6e14a6c24ae6ff74b42f7a6d8cb155cdfd1425 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='errors in upload-pack'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 D=$(pwd)