remote: fix leaking tracking refs

When computing the remote tracking ref we cause two memory leaks:

  - We leak when `remote_tracking()` fails.

  - We leak when the call to `remote_tracking()` succeeds and sets
    `ref->tracking_ref()`.

Fix both of these leaks.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-09-05 12:08:59 +02:00
committed by Junio C Hamano
parent 1e8cb17ac5
commit cdbb7208c8

View File

@ -1097,6 +1097,7 @@ void free_one_ref(struct ref *ref)
return;
free_one_ref(ref->peer_ref);
free(ref->remote_status);
free(ref->tracking_ref);
free(ref->symref);
free(ref);
}
@ -2577,8 +2578,10 @@ static int remote_tracking(struct remote *remote, const char *refname,
dst = apply_refspecs(&remote->fetch, refname);
if (!dst)
return -1; /* no tracking ref for refname at remote */
if (refs_read_ref(get_main_ref_store(the_repository), dst, oid))
if (refs_read_ref(get_main_ref_store(the_repository), dst, oid)) {
free(dst);
return -1; /* we know what the tracking ref is but we cannot read it */
}
*dst_refname = dst;
return 0;