diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-12-26 15:17:00 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-26 15:57:45 -0800 |
commit | 50571dfab38a935003806706478780bf835cc13d (patch) | |
tree | 0d24af1013f197a88907ff9ab0a7fcdb042edece /core | |
parent | 424e7570942976e2e25c4366f267c940db15d38c (diff) | |
download | subsurface-50571dfab38a935003806706478780bf835cc13d.tar.gz |
Cleanup: avoid memory leak
Coverity CID 208298
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/save-git.c | 16 |
1 files changed, 11 insertions, 5 deletions
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; } |