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

[PATCH 3/5] transport: fix leaks in refs_from_alternate_cb

From
Jeff King <peff@peff.net>
Date
Jul 24, 2014, 04:41 UTC
Message-ID
<20140724044130.GC32355@peff.net>
In-Reply-To
<20140724043940.GA31282@peff.net>

The function starts by creating a copy of the static buffer returned by real_path, but forgets to free it in the error code paths. We can solve this by jumping to the cleanup code that is already there.

Signed-off-by: Jeff King <peff@peff.net>
---
 transport.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/transport.c b/transport.c
index 3e42570..297e981 100644
--- a/transport.c
+++ b/transport.c
@@ -1359,11 +1359,11 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
 	while (other[len-1] == '/')
 		other[--len] = '\0';
 	if (len < 8 || memcmp(other + len - 8, "/objects", 8))
-		return 0;
+		goto out;
 	/* Is this a git repository with refs? */
 	memcpy(other + len - 8, "/refs", 6);
 	if (!is_directory(other))
-		return 0;
+		goto out;
 	other[len - 8] = '\0';
 	remote = remote_get(other);
 	transport = transport_get(remote, other);
@@ -1372,6 +1372,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
 	     extra = extra->next)
 		cb->fn(extra, cb->data);
 	transport_disconnect(transport);
+out:
 	free(other);
 	return 0;
 }
-- 
2.0.0.566.gfe3e6b2
Previous: Jeff KingNext: Jeff King
Message 4 of 8 in “coverity mixed bag”
  1. 0/5 coverity mixed bagJeff King, Jul 24, 2014
  2. 1/5 receive-pack: don't copy "dir" parameterJeff King, Jul 24, 2014
  3. 2/5 free ref string returned by dwim_refJeff King, Jul 24, 2014
  4. 3/5 transport: fix leaks in refs_from_alternate_cbJeff King, Jul 24, 2014
  5. 4/5 fix memory leak parsing core.commentcharJeff King, Jul 24, 2014
  6. 5/5 apply: avoid possible bogus pointerJeff King, Jul 24, 2014
  7. Junio C HamanoJul 24, 2014
  8. Stefan BellerJul 29, 2014

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.