Skip to content

Commit dde6d9c

Browse files
Laurence McGlashanLaurence McGlashan
authored andcommitted
open:move all cleanup code to cleanup label in git_repository_open_ext
1 parent b545be3 commit dde6d9c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/repository.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ int git_repository_open_ext(
800800
unsigned is_worktree;
801801
git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
802802
gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
803-
git_repository *repo;
803+
git_repository *repo = NULL;
804804
git_config *config = NULL;
805805

806806
if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
@@ -812,13 +812,8 @@ int git_repository_open_ext(
812812
error = find_repo(
813813
&gitdir, &workdir, &gitlink, &commondir, start_path, flags, ceiling_dirs);
814814

815-
if (error < 0 || !repo_ptr) {
816-
git_buf_dispose(&gitdir);
817-
git_buf_dispose(&workdir);
818-
git_buf_dispose(&gitlink);
819-
git_buf_dispose(&commondir);
820-
return error;
821-
}
815+
if (error < 0 || !repo_ptr)
816+
goto cleanup;
822817

823818
repo = repository_alloc();
824819
GIT_ERROR_CHECK_ALLOC(repo);
@@ -864,11 +859,14 @@ int git_repository_open_ext(
864859
cleanup:
865860
git_buf_dispose(&gitdir);
866861
git_buf_dispose(&workdir);
862+
git_buf_dispose(&gitlink);
863+
git_buf_dispose(&commondir);
867864
git_config_free(config);
868865

869866
if (error < 0)
870867
git_repository_free(repo);
871-
else
868+
869+
if (repo_ptr)
872870
*repo_ptr = repo;
873871

874872
return error;

0 commit comments

Comments
 (0)