Fix memory leaks when disconnecting transport instances
Most transport implementations tend to allocate a data buffer in the struct transport instance during transport_get() so we need to free that data buffer when we disconnect it. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shawn O. Pearce committed
Sep 19, 2007 at 00:49 UTC
f4e95765b042f3e31a8902e78a5101768b33e445
1 file changed
+8
transport.c
+8
@@ -236,6 +236,7 @@ static int close_bundle(struct transport *transport)
236
struct bundle_transport_data *data = transport->data;
237
if (data->fd > 0)
238
close(data->fd);
239
+ free(data);
240
return 0;
241
}
242
@@ -372,6 +373,12 @@ static int git_transport_push(struct transport *transport, int refspec_nr, const
373
return !!err;
374
}
375
376
+static int disconnect_git(struct transport *transport)
377
+{
378
+ free(transport->data);
379
+ return 0;
380
+}
381
+
382
static int is_local(const char *url)
383
{
384
const char *colon = strchr(url, ':');
@@ -419,6 +426,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
426
ret->get_refs_list = get_refs_via_connect;
427
ret->fetch = fetch_refs_via_pack;
428
ret->push = git_transport_push;
429
+ ret->disconnect = disconnect_git;
430
431
data->thin = 1;
432
data->uploadpack = "git-upload-pack";