diff options
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/commit.c b/src/commit.c index 1010fdc56..83bc9fc4c 100644 --- a/src/commit.c +++ b/src/commit.c @@ -145,8 +145,10 @@ int git_commit_create( error = git_reference_resolve(&target, head); if (error < GIT_SUCCESS) { - if (error != GIT_ENOTFOUND) + if (error != GIT_ENOTFOUND) { + git_reference_free(head); return git__rethrow(error, "Failed to create commit"); + } /* * The target of the reference was not found. This can happen * just after a repository has been initialized (the master @@ -154,10 +156,19 @@ int git_commit_create( * point to) or after an orphan checkout, so if the target * branch doesn't exist yet, create it and return. */ - return git_reference_create_oid(&head, repo, git_reference_target(head), oid, 1); + error = git_reference_create_oid(&target, repo, git_reference_target(head), oid, 1); + + git_reference_free(head); + if (error == GIT_SUCCESS) + git_reference_free(target); + + return error; } error = git_reference_set_oid(target, oid); + + git_reference_free(head); + git_reference_free(target); } if (error < GIT_SUCCESS) |