Skip to content

Commit 448d51d

Browse files
committed
transport: fix leak with transport helper URLs
Transport URLs can be prefixed with "foo::", which would tell us that the transport uses a remote helper called "foo". We extract the helper name by `xstrndup()`ing the prefix before the double-colons, but never free that string. Fix this leak by assigning the result to a separate local variable that we can then free upon returning. Helped-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 406f326 commit 448d51d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

transport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ static struct transport_vtable builtin_smart_vtable = {
11151115
struct transport *transport_get(struct remote *remote, const char *url)
11161116
{
11171117
const char *helper;
1118+
char *helper_to_free = NULL;
11181119
const char *p;
11191120
struct transport *ret = xcalloc(1, sizeof(*ret));
11201121

@@ -1139,10 +1140,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
11391140
while (is_urlschemechar(p == url, *p))
11401141
p++;
11411142
if (starts_with(p, "::"))
1142-
helper = xstrndup(url, p - url);
1143+
helper = helper_to_free = xstrndup(url, p - url);
11431144

11441145
if (helper) {
11451146
transport_helper_init(ret, helper);
1147+
free(helper_to_free);
11461148
} else if (starts_with(url, "rsync:")) {
11471149
die(_("git-over-rsync is no longer supported"));
11481150
} else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {

0 commit comments

Comments
 (0)