git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 5/5] Fix memory leaks when disconnecting transport instances

From
Shawn O. Pearce <spearce@spearce.org>
Date
Sep 19, 2007, 04:49 UTC
Message-ID
<20070919044942.GE17107@spearce.org>

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>
---
 transport.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/transport.c b/transport.c
index a1d0a3c..4f9cddc 100644
--- a/transport.c
+++ b/transport.c
@@ -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;
 }
 
@@ -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, ':');
@@ -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";
-- 
1.5.3.1.195.gadd6
Message 1 of 1 in “Fix memory leaks when disconnecting transport instances”
  1. 5/5 Fix memory leaks when disconnecting transport instancesShawn O. Pearce, Sep 19, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.