From 8960819e73d266a114f731a5a9a5dd90e5ab38bc Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 22 Aug 2024 11:18:00 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- remote.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 6ea81f9665..8f3dee1318 100644 --- 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; -- cgit v1.3