summaryrefslogtreecommitdiff
path: root/walker.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-06-05 22:37:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-06-06 17:29:12 (GMT)
commit6e454b9a31840102807f1eee527ee717bf134102 (patch)
tree44920f41fae44ba48c914b5bc13f372c539e5469 /walker.c
parentedca4152560522a431a51fc0a06147fc680b5b18 (diff)
downloadgit-6e454b9a31840102807f1eee527ee717bf134102.zip
git-6e454b9a31840102807f1eee527ee717bf134102.tar.gz
git-6e454b9a31840102807f1eee527ee717bf134102.tar.bz2
clear parsed flag when we free tree buffers
Many code paths will free a tree object's buffer and set it to NULL after finishing with it in order to keep memory usage down during a traversal. However, out of 8 sites that do this, only one actually unsets the "parsed" flag back. Those sites that don't are setting a trap for later users of the tree object; even after calling parse_tree, the buffer will remain NULL, causing potential segfaults. It is not known whether this is triggerable in the current code. Most commands do not do an in-memory traversal followed by actually using the objects again. However, it does not hurt to be safe for future callers. In most cases, we can abstract this out to a "free_tree_buffer" helper. However, there are two exceptions: 1. The fsck code relies on the parsed flag to know that we were able to parse the object at one point. We can switch this to using a flag in the "flags" field. 2. The index-pack code sets the buffer to NULL but does not free it (it is freed by a caller). We should still unset the parsed flag here, but we cannot use our helper, as we do not want to free the buffer. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'walker.c')
-rw-r--r--walker.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/walker.c b/walker.c
index be389dc..633596e 100644
--- a/walker.c
+++ b/walker.c
@@ -56,10 +56,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
if (!obj || process(walker, obj))
return -1;
}
- free(tree->buffer);
- tree->buffer = NULL;
- tree->size = 0;
- tree->object.parsed = 0;
+ free_tree_buffer(tree);
return 0;
}