@matheusbsbs / matheus-bagliano / commits / 7e18e56920
Fork 0

git-tar-tree: fix minor memory leak

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Rene Scharfe committed Aug 4, 2006 at 10:54 UTC 7e18e56920bd38ffc1f2c068d943bfd3f012473d
1 file changed +4 -2
builtin-tar-tree.c
+4 -2
@@ -314,6 +314,7 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
314 struct commit *commit;
315 struct tree_desc tree;
316 struct strbuf current_path;
317 + void *buffer;
318
319 current_path.buf = xmalloc(PATH_MAX);
320 current_path.alloc = PATH_MAX;
@@ -341,8 +342,8 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
342 } else
343 archive_time = time(NULL);
344
344 - tree.buf = read_object_with_reference(sha1, tree_type, &tree.size,
345 - tree_sha1);
345 + tree.buf = buffer = read_object_with_reference(sha1, tree_type,
346 + &tree.size, tree_sha1);
347 if (!tree.buf)
348 die("not a reference to a tag, commit or tree object: %s",
349 sha1_to_hex(sha1));
@@ -351,6 +352,7 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
352 write_entry(tree_sha1, &current_path, 040777, NULL, 0);
353 traverse_tree(&tree, &current_path);
354 write_trailer();
355 + free(buffer);
356 free(current_path.buf);
357 return 0;
358 }