Skip to content

Commit

Permalink
Fix memory leaks when disconnecting transport instances
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Sep 19, 2007
1 parent 50ab5fd commit f4e9576
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ static int close_bundle(struct transport *transport)
struct bundle_transport_data *data = transport->data;
if (data->fd > 0)
close(data->fd);
free(data);
return 0;
}

Expand Down Expand Up @@ -372,6 +373,12 @@ static int git_transport_push(struct transport *transport, int refspec_nr, const
return !!err;
}

static int disconnect_git(struct transport *transport)
{
free(transport->data);
return 0;
}

static int is_local(const char *url)
{
const char *colon = strchr(url, ':');
Expand Down Expand Up @@ -419,6 +426,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
ret->get_refs_list = get_refs_via_connect;
ret->fetch = fetch_refs_via_pack;
ret->push = git_transport_push;
ret->disconnect = disconnect_git;

data->thin = 1;
data->uploadpack = "git-upload-pack";
Expand Down

0 comments on commit f4e9576

Please sign in to comment.