builtin/clone: plug leaking HEAD ref in `wanted_peer_refs()`
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>
Patrick Steinhardt committed
Jun 11, 2024 at 11:20 UTC
8909d6e1a108a46ae9cde70587aa8b2ad4a067d9
4 files changed
+6
-3
builtin/clone.c
+2
-1
@@ -530,7 +530,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
530
if (!option_branch)
531
remote_head = guess_remote_head(head, refs, 0);
532
else {
533
- local_refs = NULL;
533
+ free_one_ref(head);
534
+ local_refs = head = NULL;
535
tail = &local_refs;
536
remote_head = copy_ref(find_remote_branch(refs, option_branch));
537
}
t/t5300-pack-object.sh
+2
-2
@@ -3,9 +3,9 @@
3
# Copyright (c) 2005 Junio C Hamano
4
#
5
6
-test_description='git pack-object
6
+test_description='git pack-object'
7
8
-'
8
+TEST_PASSES_SANITIZE_LEAK=true
9
. ./test-lib.sh
10
11
test_expect_success 'setup' '
t/t5305-include-tag.sh
+1
@@ -4,6 +4,7 @@ test_description='git pack-object --include-tag'
4
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7
+TEST_PASSES_SANITIZE_LEAK=true
8
. ./test-lib.sh
9
10
TRASH=$(pwd)
t/t5612-clone-refspec.sh
+1
@@ -4,6 +4,7 @@ test_description='test refspec written by clone-command'
4
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7
+TEST_PASSES_SANITIZE_LEAK=true
8
. ./test-lib.sh
9
10
test_expect_success 'setup' '