transport-helper: fix leaking helper name
When initializing the transport helper in `transport_get()`, we allocate the name of the helper. We neither end up transferring ownership of the name, nor do we free it. The associated memory thus leaks. Fix this memory leak by freeing the string at the calling side in `transport_get()`. `transport_helper_init()` now creates its own copy of the string and thus can free it as required. An alterantive way to fix this would be to transfer ownership of the string passed into `transport_helper_init()`, which would avoid the call to xstrdup(1). But it does make for a more surprising calling convention as we do not typically transfer ownership of strings like this. Mark now-passing tests as leak free. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
fba95dad6a
commit
97613b9cb9
@ -1176,6 +1176,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
|
||||
int len = external_specification_len(url);
|
||||
char *handler = xmemdupz(url, len);
|
||||
transport_helper_init(ret, handler);
|
||||
free(handler);
|
||||
}
|
||||
|
||||
if (ret->smart_options) {
|
||||
|
Reference in New Issue
Block a user