Message ID | 7fafcc53d23672bb0339c44ea3874b3628785f08.1724656120.git.ps@pks.im (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Memory leak fixes (pt.6) | expand |
Patrick Steinhardt <ps@pks.im> writes: > @@ -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; Looking good.
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;
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(-)