summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/commit.c b/src/commit.c
index b9eb3650..83bc9fc4 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -137,15 +137,18 @@ int git_commit_create(
if (error == GIT_SUCCESS && update_ref != NULL) {
git_reference *head;
+ git_reference *target;
error = git_reference_lookup(&head, repo, update_ref);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to create commit");
- error = git_reference_resolve(&head, head);
+ 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
@@ -153,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(head, oid);
+ error = git_reference_set_oid(target, oid);
+
+ git_reference_free(head);
+ git_reference_free(target);
}
if (error < GIT_SUCCESS)