Skip to content

Commit 06abbb7

Browse files
committed
treebuilder: exit early if running OOM in write_with_buffer
While writing the tree inside of a buffer, we check whether the buffer runs out of memory after each tree entry. While we set the error code as soon as we detect the OOM situation, we happily proceed iterating over the entries. This is not useful at all, as we will try to write into the buffer repeatedly, which cannot work. Fix this by exiting as soon as we are OOM.
1 parent 8d1e71f commit 06abbb7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/tree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,12 +847,13 @@ int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_bu
847847
git_buf_put(tree, entry->filename, entry->filename_len + 1);
848848
git_buf_put(tree, (char *)entry->oid->id, GIT_OID_RAWSZ);
849849

850-
if (git_buf_oom(tree))
850+
if (git_buf_oom(tree)) {
851851
error = -1;
852+
goto out;
853+
}
852854
}
853855

854-
if (!error &&
855-
!(error = git_repository_odb__weakptr(&odb, bld->repo)))
856+
if ((error = git_repository_odb__weakptr(&odb, bld->repo)) == 0)
856857
error = git_odb_write(oid, odb, tree->ptr, tree->size, GIT_OBJ_TREE);
857858

858859
out:

0 commit comments

Comments
 (0)