Commit f647d021 by Patrick Steinhardt

iterator: avoid leaving partially initialized frame on stack

When allocating tree iterator entries, we use GIT_ERROR_ALLOC_CHECK` to
check whether the allocation has failed. The macro will cause the
function to immediately return, though, leaving behind a partially
initialized iterator frame.

Fix the issue by manually checking for memory allocation errors and
using `goto done` in case of an error, popping the iterator frame.
parent ad735bf3
......@@ -563,8 +563,11 @@ static int tree_iterator_frame_init(
goto done;
git_array_foreach(dup->entries, i, tree_entry) {
new_entry = git_pool_malloc(&iter->entry_pool, 1);
GIT_ERROR_CHECK_ALLOC(new_entry);
if ((new_entry = git_pool_malloc(&iter->entry_pool, 1)) == NULL) {
git_error_set_oom();
error = -1;
goto done;
}
new_entry->tree_entry = tree_entry;
new_entry->parent_path = new_frame->path.ptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment