@@ -818,43 +818,45 @@ int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_bu
818818 size_t i , entrycount ;
819819 git_odb * odb ;
820820 git_tree_entry * entry ;
821- git_vector entries ;
821+ git_vector entries = GIT_VECTOR_INIT ;
822822
823823 assert (bld );
824824 assert (tree );
825825
826826 git_buf_clear (tree );
827827
828828 entrycount = git_strmap_num_entries (bld -> map );
829- if (git_vector_init (& entries , entrycount , entry_sort_cmp ) < 0 )
830- return -1 ;
829+ if (( error = git_vector_init (& entries , entrycount , entry_sort_cmp ) ) < 0 )
830+ goto out ;
831831
832832 if (tree -> asize == 0 &&
833- (error = git_buf_grow (tree , entrycount * 72 )) < 0 )
834- return error ;
833+ (error = git_buf_grow (tree , entrycount * 72 )) < 0 )
834+ goto out ;
835835
836836 git_strmap_foreach_value (bld -> map , entry , {
837- if (git_vector_insert (& entries , entry ) < 0 )
838- return -1 ;
837+ if (( error = git_vector_insert (& entries , entry ) ) < 0 )
838+ goto out ;
839839 });
840840
841841 git_vector_sort (& entries );
842842
843843 for (i = 0 ; i < entries .length && !error ; ++ i ) {
844- git_tree_entry * entry = git_vector_get (& entries , i );
844+ entry = git_vector_get (& entries , i );
845845
846846 git_buf_printf (tree , "%o " , entry -> attr );
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
859+ out :
858860 git_vector_free (& entries );
859861
860862 return error ;
0 commit comments