diff options
| author | Patrick Steinhardt <ps@pks.im> | 2019-08-27 10:36:20 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-08-27 10:48:26 +0200 |
| commit | 9ca7a60e68d72d6e1da6eac519de48ecfca6d7f1 (patch) | |
| tree | 3ac1b3bfb7416f94f2fe7461c54ed1a6e907cbe6 /src | |
| parent | fe241071317a69dbda10b821fbc909edca2367fb (diff) | |
| download | libgit2-9ca7a60e68d72d6e1da6eac519de48ecfca6d7f1.tar.gz | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/iterator.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/iterator.c b/src/iterator.c index 3cfbd1f96..e95aed70b 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -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; |
