summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-02-16 13:08:55 +0000
committerEdward Thomson <ethomson@github.com>2016-02-17 13:10:33 +0000
commit4fea9cffbda89562bfdcdd58b0162d31ca4feb3e (patch)
treee1de040e8db998c61b57ee0ee75598c325a755e8
parenta218b2f625874d9d9523f05a86845506c4735e66 (diff)
downloadlibgit2-4fea9cffbda89562bfdcdd58b0162d31ca4feb3e.tar.gz
iterator: assert tree_iterator has a frame
Although a `tree_iterator` that failed to be properly created does not have a frame, all other `tree_iterator`s should. Do not call `pop` in the failure case, but assert that in all other cases there is a frame.
-rw-r--r--src/iterator.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/iterator.c b/src/iterator.c
index 2d9ebf41d..973f77b03 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -558,7 +558,9 @@ static bool tree_iterator__pop_frame(tree_iterator *ti, bool final)
{
tree_iterator_frame *tf = ti->head;
- if (!tf || !tf->up)
+ assert(tf);
+
+ if (!tf->up)
return false;
ti->head = tf->up;
@@ -581,8 +583,9 @@ static void tree_iterator__pop_all(tree_iterator *ti, bool to_end, bool final)
while (tree_iterator__pop_frame(ti, final)) /* pop to root */;
if (!final) {
- if(ti->head)
- ti->head->current = to_end ? ti->head->n_entries : 0;
+ assert(ti->head);
+
+ ti->head->current = to_end ? ti->head->n_entries : 0;
ti->path_ambiguities = 0;
git_buf_clear(&ti->path);
}
@@ -774,11 +777,12 @@ static void tree_iterator__free(git_iterator *self)
{
tree_iterator *ti = (tree_iterator *)self;
- tree_iterator__pop_all(ti, true, false);
-
- if(ti->head)
+ if (ti->head) {
+ tree_iterator__pop_all(ti, true, false);
git_tree_free(ti->head->entries[0]->tree);
- git__free(ti->head);
+ git__free(ti->head);
+ }
+
git_pool_clear(&ti->pool);
git_buf_free(&ti->path);
}