Skip to content

Commit 8960819

Browse files
pks-tgitster
authored andcommitted
remote: fix leaking peer ref when expanding refmap
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e9e04a commit 8960819

File tree

5 files changed

+6
-0
lines changed

5 files changed

+6
-0
lines changed

remote.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,8 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
20812081
!ignore_symref_update(expn_name, &scratch)) {
20822082
struct ref *cpy = copy_ref(ref);
20832083

2084+
if (cpy->peer_ref)
2085+
free_one_ref(cpy->peer_ref);
20842086
cpy->peer_ref = alloc_ref(expn_name);
20852087
if (refspec->force)
20862088
cpy->peer_ref->force = 1;

t/t5536-fetch-conflicts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='fetch handles conflicting refspecs correctly'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
D=$(pwd)

t/t5553-set-upstream.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_description='"git fetch/pull --set-upstream" basic tests.'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

7+
TEST_PASSES_SANITIZE_LEAK=true
78
. ./test-lib.sh
89

910
check_config () {

t/t5703-upload-pack-ref-in-want.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='upload-pack ref-in-want'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
get_actual_refs () {

t/t6050-replace.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_description='Tests replace refs functionality'
77
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
88
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
99

10+
TEST_PASSES_SANITIZE_LEAK=true
1011
. ./test-lib.sh
1112
. "$TEST_DIRECTORY/lib-gpg.sh"
1213

0 commit comments

Comments
 (0)