open:move all cleanup code to cleanup label in git_repository_open_ext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/src/repository.c b/src/repository.c
index e1e3ef0..2cb59e0 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -800,7 +800,7 @@ int git_repository_open_ext(
unsigned is_worktree;
git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
- git_repository *repo;
+ git_repository *repo = NULL;
git_config *config = NULL;
if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
@@ -812,13 +812,8 @@ int git_repository_open_ext(
error = find_repo(
&gitdir, &workdir, &gitlink, &commondir, start_path, flags, ceiling_dirs);
- if (error < 0 || !repo_ptr) {
- git_buf_dispose(&gitdir);
- git_buf_dispose(&workdir);
- git_buf_dispose(&gitlink);
- git_buf_dispose(&commondir);
- return error;
- }
+ if (error < 0 || !repo_ptr)
+ goto cleanup;
repo = repository_alloc();
GIT_ERROR_CHECK_ALLOC(repo);
@@ -864,11 +859,14 @@ int git_repository_open_ext(
cleanup:
git_buf_dispose(&gitdir);
git_buf_dispose(&workdir);
+ git_buf_dispose(&gitlink);
+ git_buf_dispose(&commondir);
git_config_free(config);
if (error < 0)
git_repository_free(repo);
- else
+
+ if (repo_ptr)
*repo_ptr = repo;
return error;