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

[PATCH] git-tar-tree: fix minor memory leak

From
Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Aug 4, 2006, 08:54 UTC
Message-ID
<20060804085408.GA22305@lsrfire.ath.cx>

Free the root tree object buffer when we're done, plugging a minor leak in generate_tar(). Note: we cannot simply free(tree.buf) because this pointer is modified by tree_entry() calls in traverse_tree().

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
My first Valgrind run. :)
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 7c48db9..215892b 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -314,6 +314,7 @@ static int generate_tar(int argc, const 
 	struct commit *commit;
 	struct tree_desc tree;
 	struct strbuf current_path;
+	void *buffer;
 
 	current_path.buf = xmalloc(PATH_MAX);
 	current_path.alloc = PATH_MAX;
@@ -341,8 +342,8 @@ static int generate_tar(int argc, const 
 	} else
 		archive_time = time(NULL);
 
-	tree.buf = read_object_with_reference(sha1, tree_type, &tree.size,
-	                                      tree_sha1);
+	tree.buf = buffer = read_object_with_reference(sha1, tree_type,
+	                                               &tree.size, tree_sha1);
 	if (!tree.buf)
 		die("not a reference to a tag, commit or tree object: %s",
 		    sha1_to_hex(sha1));
@@ -351,6 +352,7 @@ static int generate_tar(int argc, const 
 		write_entry(tree_sha1, &current_path, 040777, NULL, 0);
 	traverse_tree(&tree, &current_path);
 	write_trailer();
+	free(buffer);
 	free(current_path.buf);
 	return 0;
 }
Message 1 of 1 in “git-tar-tree: fix minor memory leak”
  1. git-tar-tree: fix minor memory leakRene Scharfe, Aug 4, 2006

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.