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

[PATCH] Fix memory leaks in read_tree_recursive()

From
Jonas Fonseca <fonseca@diku.dk>
Date
May 4, 2005, 23:39 UTC
Message-ID
<20050504233936.GA25873@diku.dk>
In-Reply-To
<20050504231959.GA25475@diku.dk>
This patch fixes memory leaks in read_tree_recursive().
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---

Sorry, typo in the previous patch. I will try to be more careful. This patch has already been applied to cogito.

--- 571c0f4599fbeefd995bbc24480add1575c36c94/tree.c (mode:100644 sha1:4a26603f6e32866c0db8a01ac1c228be801f76c6) +++ uncommitted/tree.c (mode:100644)

@@ -39,14 +39,18 @@
 		if (S_ISDIR(mode)) {
 			int retval;
 			int pathlen = strlen(path);
-			char *newbase = xmalloc(baselen + 1 + pathlen);
+			char *newbase;
 			void *eltbuf;
 			char elttype[20];
 			unsigned long eltsize;
 
 			eltbuf = read_sha1_file(sha1, elttype, &eltsize);
-			if (!eltbuf || strcmp(elttype, "tree"))
+			if (!eltbuf || strcmp(elttype, "tree")) {
+				if (eltbuf) free(eltbuf);
 				return -1;
+			}
+
+			newbase = xmalloc(baselen + 1 + pathlen);
 			memcpy(newbase, base, baselen);
 			memcpy(newbase + baselen, path, pathlen);
 			newbase[baselen + pathlen] = '/';
-- 
Jonas Fonseca
Previous: Jonas FonsecaNext: Junio C Hamano
Message 2 of 4 in “Fix memory leaks in read_tree_recursive()”
  1. Fix memory leaks in read_tree_recursive()Jonas Fonseca, May 4, 2005
  2. Fix memory leaks in read_tree_recursive()Jonas Fonseca, May 4, 2005
  3. Junio C HamanoMay 4, 2005
  4. Jonas FonsecaMay 5, 2005

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.