From 50571dfab38a935003806706478780bf835cc13d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 26 Dec 2017 15:17:00 -0800 Subject: Cleanup: avoid memory leak Coverity CID 208298 Signed-off-by: Dirk Hohndel --- core/save-git.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/save-git.c b/core/save-git.c index e5ff5378b..227430a2e 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -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; } -- cgit v1.2.3-70-g09d2