]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: fix leaking peer ref when expanding refmap
authorPatrick Steinhardt <ps@pks.im>
Thu, 22 Aug 2024 09:18:00 +0000 (11:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2024 16:18:06 +0000 (09:18 -0700)
When expanding remote refs via the refspec in `get_expanded_map()`, we
first copy the remote ref and then override its peer ref with the
expanded name. This may cause a memory leak though in case the peer ref
is already set, as this field is being copied by `copy_ref()`, as well.

Fix the leak by freeing the peer ref before we re-assign the field.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c
t/t5536-fetch-conflicts.sh
t/t5553-set-upstream.sh
t/t5703-upload-pack-ref-in-want.sh
t/t6050-replace.sh

index 6ea81f9665b5508805d039485f53113181a5b854..8f3dee13186e7c539c077b81d123b7b50131300e 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -2081,6 +2081,8 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
                    !ignore_symref_update(expn_name, &scratch)) {
                        struct ref *cpy = copy_ref(ref);
 
+                       if (cpy->peer_ref)
+                               free_one_ref(cpy->peer_ref);
                        cpy->peer_ref = alloc_ref(expn_name);
                        if (refspec->force)
                                cpy->peer_ref->force = 1;
index 23bf69617007d7e97ff3641d3a5783a7ffe0352a..2dcbe790523cc3e53ad6ad100242d52f92fabf51 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='fetch handles conflicting refspecs correctly'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 D=$(pwd)
index 70e3376d31b4311764be51360acd86447e885a31..33e919a17e1670a40d6d55cd57e0d5f0469dd779 100755 (executable)
@@ -4,6 +4,7 @@ test_description='"git fetch/pull --set-upstream" basic tests.'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 check_config () {
index 191097171bcbd4d16f107430af4ee4bb4c14493a..f75fae52c83d8b2fb300a1a323b11806fc7c3ecc 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='upload-pack ref-in-want'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 get_actual_refs () {
index c6e9b33e44edf4d2d7ecefe688ca6df5fc82d112..d7702fc7562332fc05820bade8d644b02c35803d 100755 (executable)
@@ -7,6 +7,7 @@ test_description='Tests replace refs functionality'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY/lib-gpg.sh"