Merge pull request #5361 from csware/no-return-freed_object Do not return free'd git_repository object on error
diff --git a/src/repository.c b/src/repository.c
index 14968d7..03f6820 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -865,8 +865,7 @@ cleanup:
if (error < 0)
git_repository_free(repo);
-
- if (repo_ptr)
+ else if (repo_ptr)
*repo_ptr = repo;
return error;
diff --git a/tests/repo/open.c b/tests/repo/open.c
index 83b53c4..448ccdc 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -277,7 +277,9 @@ void test_repo_open__bad_gitlinks(void)
for (scan = bad_links; *scan != NULL; scan++) {
make_gitlink_dir("alternate", *scan);
+ repo = NULL;
cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
+ cl_assert(repo == NULL);
}
git_futils_rmdir_r("invalid", NULL, GIT_RMDIR_REMOVE_FILES);