1
0
mirror of https://github.com/git/git.git synced 2024-10-18 12:18:44 +02:00

transport-helper: fix leak of dummy refs_list

When using a remote-helper, the fetch_refs() function will issue a
"list" command if we haven't already done so. We don't care about the
result, but this is just to maintain compatibility as explained in
ac3fda82bf (transport-helper: skip ls-refs if unnecessary, 2019-08-21).

But get_refs_list_using_list(), the function we call to issue the
command, does parse and return the resulting ref list, which we simply
leak. We should record the return value and free it immediately (another
approach would be to teach it to avoid allocating at all, but it does
not seem worth the trouble to micro-optimize this mostly historical
case).

Triggering this requires the v0 protocol (since in v2 we use stateless
connect to take over the connection). You can see it in t5551.37, "fetch
by SHA-1 without tag following", as it explicitly enables v0.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2024-09-24 17:58:47 -04:00 committed by Junio C Hamano
parent d121a7dd21
commit cb2732f0ca

@ -717,8 +717,14 @@ static int fetch_refs(struct transport *transport,
return -1; return -1;
} }
if (!data->get_refs_list_called) if (!data->get_refs_list_called) {
get_refs_list_using_list(transport, 0); /*
* We do not care about the list of refs returned, but only
* that the "list" command was sent.
*/
struct ref *dummy = get_refs_list_using_list(transport, 0);
free_refs(dummy);
}
count = 0; count = 0;
for (i = 0; i < nr_heads; i++) for (i = 0; i < nr_heads; i++)