1
0
Fork 0
mirror of https://github.com/subsurface/subsurface.git synced 2025-02-19 22:16:15 +00:00

Cleanup: avoid memory leak

Coverity CID 208298

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-12-26 15:17:00 -08:00
parent 424e757094
commit 50571dfab3

View file

@ -1151,22 +1151,30 @@ static int create_new_commit(git_repository *repo, const char *remote, const cha
/* If the parent commit has the same tree ID, do not create a new commit */
if (parent && git_oid_equal(tree_id, git_commit_tree_id((const git_commit *) parent))) {
/* If the parent already came from the ref, the commit is already there */
if (ref)
if (ref) {
git_signature_free(author);
return 0;
}
/* Else we do want to create the new branch, but with the old commit */
commit = (git_commit *) parent;
} else {
struct membuffer commit_msg = { 0 };
create_commit_message(&commit_msg, create_empty);
if (git_commit_create_v(&commit_id, repo, NULL, author, author, NULL, mb_cstring(&commit_msg), tree, parent != NULL, parent))
if (git_commit_create_v(&commit_id, repo, NULL, author, author, NULL, mb_cstring(&commit_msg), tree, parent != NULL, parent)) {
git_signature_free(author);
return report_error("Git commit create failed (%s)", strerror(errno));
}
free_buffer(&commit_msg);
if (git_commit_lookup(&commit, repo, &commit_id))
if (git_commit_lookup(&commit, repo, &commit_id)) {
git_signature_free(author);
return report_error("Could not look up newly created commit");
}
}
git_signature_free(author);
if (!ref) {
if (git_branch_create(&ref, repo, branch, commit, 0))
return report_error("Failed to create branch '%s'", branch);
@ -1198,8 +1206,6 @@ static int create_new_commit(git_repository *repo, const char *remote, const cha
if (! create_empty)
set_git_id(&commit_id);
git_signature_free(author);
return 0;
}