]> git.ipfire.org Git - thirdparty/git.git/commit
remote: refactor alias_url() memory ownership
authorJeff King <peff@peff.net>
Fri, 14 Jun 2024 10:26:16 +0000 (06:26 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jun 2024 16:34:37 +0000 (09:34 -0700)
commitaa0595fbd635bc2d16a4921244cf2bc94ca7761e
tree8511784f4fbc9375382a23fd4068cd6655a9ade4
parent0295ce7cbf0d2b3b71f44d9dc84ae8db1e895a99
remote: refactor alias_url() memory ownership

The alias_url() function may return either a newly allocated string
(which the caller must take ownership of), or the original const "url"
parameter that was passed in.

This often works OK because callers are generally passing in a "url"
that they expect to retain ownership of anyway. So whether we got back
the original or a new string, we're always interested in storing it
forever. But I suspect there are some possible leaks here (e.g.,
add_url_alias() may end up discarding the original "url").

Whether there are active leaks or not, this is a confusing setup that
makes further refactoring of memory ownership harder. So instead of
returning the original string, return NULL, forcing callers to decide
what to do with it explicitly. We can then build further cleanups on top
of that.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c