]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/clone: plug leaking HEAD ref in `wanted_peer_refs()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Jun 2024 09:20:57 +0000 (11:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Jun 2024 20:15:07 +0000 (13:15 -0700)
In `wanted_peer_refs()` we first create a copy of the "HEAD" ref. This
copy may not actually be passed back to the caller, but is not getting
freed in this case. Fix this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
t/t5300-pack-object.sh
t/t5305-include-tag.sh
t/t5612-clone-refspec.sh

index 730b3efae6085555d8e1b454903efce1726b41c5..ae9863ed477c26f25f9a2edd664a66b9d7601e53 100644 (file)
@@ -530,7 +530,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
                if (!option_branch)
                        remote_head = guess_remote_head(head, refs, 0);
                else {
-                       local_refs = NULL;
+                       free_one_ref(head);
+                       local_refs = head = NULL;
                        tail = &local_refs;
                        remote_head = copy_ref(find_remote_branch(refs, option_branch));
                }
index 61e2be2903d344563fe2ebea718de962e60d7b78..4ad023c846d06ad8eceadcd8bac57599a992648b 100755 (executable)
@@ -3,9 +3,9 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-test_description='git pack-object
+test_description='git pack-object'
 
-'
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
index 44bd9ef45fd6d320e50f00fb0f86505fac2d7955..dc8fe55c82d5ee146014f4b3d5f478d13fdc75f1 100755 (executable)
@@ -4,6 +4,7 @@ test_description='git pack-object --include-tag'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 TRASH=$(pwd)
index 3126cfd7e9d6bdcd41f2c65811b8a2ff8fe0f16e..72762de9774caa7a3d02b6a3539cd3372b24c3ad 100755 (executable)
@@ -4,6 +4,7 @@ test_description='test refspec written by clone-command'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '