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>
This commit is contained in:

committed by
Junio C Hamano

parent
d249b45547
commit
7e18e56920
@ -314,6 +314,7 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
|
|||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
struct tree_desc tree;
|
struct tree_desc tree;
|
||||||
struct strbuf current_path;
|
struct strbuf current_path;
|
||||||
|
void *buffer;
|
||||||
|
|
||||||
current_path.buf = xmalloc(PATH_MAX);
|
current_path.buf = xmalloc(PATH_MAX);
|
||||||
current_path.alloc = PATH_MAX;
|
current_path.alloc = PATH_MAX;
|
||||||
@ -341,8 +342,8 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
|
|||||||
} else
|
} else
|
||||||
archive_time = time(NULL);
|
archive_time = time(NULL);
|
||||||
|
|
||||||
tree.buf = read_object_with_reference(sha1, tree_type, &tree.size,
|
tree.buf = buffer = read_object_with_reference(sha1, tree_type,
|
||||||
tree_sha1);
|
&tree.size, tree_sha1);
|
||||||
if (!tree.buf)
|
if (!tree.buf)
|
||||||
die("not a reference to a tag, commit or tree object: %s",
|
die("not a reference to a tag, commit or tree object: %s",
|
||||||
sha1_to_hex(sha1));
|
sha1_to_hex(sha1));
|
||||||
@ -351,6 +352,7 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
|
|||||||
write_entry(tree_sha1, ¤t_path, 040777, NULL, 0);
|
write_entry(tree_sha1, ¤t_path, 040777, NULL, 0);
|
||||||
traverse_tree(&tree, ¤t_path);
|
traverse_tree(&tree, ¤t_path);
|
||||||
write_trailer();
|
write_trailer();
|
||||||
|
free(buffer);
|
||||||
free(current_path.buf);
|
free(current_path.buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user