Skip to content

Commit 9ca7a60

Browse files
committed
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.
1 parent fe24107 commit 9ca7a60

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/iterator.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,11 @@ static int tree_iterator_frame_init(
563563
goto done;
564564

565565
git_array_foreach(dup->entries, i, tree_entry) {
566-
new_entry = git_pool_malloc(&iter->entry_pool, 1);
567-
GIT_ERROR_CHECK_ALLOC(new_entry);
566+
if ((new_entry = git_pool_malloc(&iter->entry_pool, 1)) == NULL) {
567+
git_error_set_oom();
568+
error = -1;
569+
goto done;
570+
}
568571

569572
new_entry->tree_entry = tree_entry;
570573
new_entry->parent_path = new_frame->path.ptr;

0 commit comments

Comments
 (0)