Re: [PATCH 02/11] clone: fix memory leak in copy_ref() call
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 30, 2022, 22:03 UTC
- Message-ID
- <xmqq7d4xdd1o.fsf@gitster.g>
- In-Reply-To
- <patch-02.11-8e424238071-20220630T175714Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Fix a memory leak added in 0ec4b1650cc (clone: fix ref selection in > --single-branch --branch=xxx, 2012-06-22), we need to free_refs() the > result of copy_ref().
remote_head could be the result of guess_remote_head(), instead of copy_ref(), and in either case, once we are done with it, we need to and can safely free it.
Show 9 quoted lines
> diff --git a/builtin/clone.c b/builtin/clone.c > index 89a91b00177..c43c85dad07 100644 > --- a/builtin/clone.c > +++ b/builtin/clone.c > @@ -494,6 +494,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs, > /* if --branch=tag, pull the requested tag explicitly */ > get_fetch_map(remote_head, tag_refspec, &tail, 0); > } > + free_refs(remote_head);
Looks good.
> } else {
> int i;
> for (i = 0; i < refspec->nr; i++)