Skip to content

Commit cb2732f

Browse files
peffgitster
authored andcommitted
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 ac3fda8 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d121a7d commit cb2732f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

transport-helper.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,14 @@ static int fetch_refs(struct transport *transport,
717717
return -1;
718718
}
719719

720-
if (!data->get_refs_list_called)
721-
get_refs_list_using_list(transport, 0);
720+
if (!data->get_refs_list_called) {
721+
/*
722+
* We do not care about the list of refs returned, but only
723+
* that the "list" command was sent.
724+
*/
725+
struct ref *dummy = get_refs_list_using_list(transport, 0);
726+
free_refs(dummy);
727+
}
722728

723729
count = 0;
724730
for (i = 0; i < nr_heads; i++)

0 commit comments

Comments
 (0)