diff mbox series

[v2,08/22] remote: fix leaking tracking refs

Message ID 90647301de58b519f36fb0d677ed7be99924769b.1725530720.git.ps@pks.im (mailing list archive)
State Accepted
Commit cdbb7208c80661754b3f1a73aef086c08f88dcff
Headers show
Series Memory leak fixes (pt.6) | expand

Commit Message

Patrick Steinhardt Sept. 5, 2024, 10:08 a.m. UTC
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>
---
 remote.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/remote.c b/remote.c
index 8f3dee13186..240311619ab 100644
--- a/remote.c
+++ b/remote.c
@@ -1123,6 +1123,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);
 }
@@ -2620,8 +2621,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;