{"thread":{"id":"5116","subject":"[PATCH] git-tar-tree: fix minor memory leak","startedAt":"2006-08-04T08:54:08Z","lastAt":"2006-08-04T08:54:08Z","messageCount":1,"participants":["Rene Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"24694","messageId":"20060804085408.GA22305@lsrfire.ath.cx","threadId":"5116","inReplyTo":null,"subject":"[PATCH] git-tar-tree: fix minor memory leak","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2006-08-04T08:54:08Z","receivedAt":"2006-08-04T08:54:08Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Free the root tree object buffer when we're done, plugging a minor leak\nin generate_tar().  Note: we cannot simply free(tree.buf) because this\npointer is modified by tree_entry() calls in traverse_tree().\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n\nMy first Valgrind run. :)\n\n\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex 7c48db9..215892b 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -314,6 +314,7 @@ static int generate_tar(int argc, const \n \tstruct commit *commit;\n \tstruct tree_desc tree;\n \tstruct strbuf current_path;\n+\tvoid *buffer;\n \n \tcurrent_path.buf = xmalloc(PATH_MAX);\n \tcurrent_path.alloc = PATH_MAX;\n@@ -341,8 +342,8 @@ static int generate_tar(int argc, const \n \t} else\n \t\tarchive_time = time(NULL);\n \n-\ttree.buf = read_object_with_reference(sha1, tree_type, &tree.size,\n-\t                                      tree_sha1);\n+\ttree.buf = buffer = read_object_with_reference(sha1, tree_type,\n+\t                                               &tree.size, tree_sha1);\n \tif (!tree.buf)\n \t\tdie(\"not a reference to a tag, commit or tree object: %s\",\n \t\t    sha1_to_hex(sha1));\n@@ -351,6 +352,7 @@ static int generate_tar(int argc, const \n \t\twrite_entry(tree_sha1, &current_path, 040777, NULL, 0);\n \ttraverse_tree(&tree, &current_path);\n \twrite_trailer();\n+\tfree(buffer);\n \tfree(current_path.buf);\n \treturn 0;\n }\n"}]}