summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurence McGlashan <Laurence.McGlashan@mathworks.co.uk>2019-09-10 17:09:57 +0100
committerPatrick Steinhardt <ps@pks.im>2020-03-26 16:20:18 +0100
commit51fb0c156d7ee236879752b6e3f44110a579fde9 (patch)
treef07a055322e7fec99e563dace18361ce22bd99ff
parent8c99ccc5d555dc04369bfd16dcbc4c4d5778a10f (diff)
downloadlibgit2-51fb0c156d7ee236879752b6e3f44110a579fde9.tar.gz
open:move all cleanup code to cleanup label in git_repository_open_ext
-rw-r--r--src/repository.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/repository.c b/src/repository.c
index cb6be60b4..ddbf2626d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -799,7 +799,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)
@@ -811,13 +811,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);
@@ -863,11 +858,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;