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

[PATCH] read_tree_recursive(): Fix leaks

From
Jonas Fonseca <fonseca@diku.dk>
Date
Apr 26, 2005, 23:00 UTC
Message-ID
<20050426230001.GB28560@diku.dk>
Fix two potential leaks.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

--- commit 74f5ad9d566408b4d352570ccde67ece0f2650a7 tree 7a6c485bceed70459c1855ab3c4d8ddfdeeb65d1 parent a738ed98e4557877f8bcd3b992aa55579b22b9d1 author Jonas Fonseca <fonseca@diku.dk> 1114555146 +0200 committer Jonas Fonseca <fonseca@diku.dk> 1114555146 +0200

 tree.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
Index: tree.c
===================================================================
--- 2447d3a399200c8f736344822969f88f675612dd/tree.c  (mode:100644 sha1:15a16d560619aee80e41bf816dd8474a3253b1a5)
+++ 7a6c485bceed70459c1855ab3c4d8ddfdeeb65d1/tree.c  (mode:100644 sha1:7c55bb9bfa1565dc9df5cab31207a02004d7fe10)
@@ -39,14 +39,17 @@
 		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
Message 1 of 1 in “read_tree_recursive(): Fix leaks”
  1. read_tree_recursive(): Fix leaksJonas Fonseca, Apr 26, 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.