mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 20:42:23 +00:00
branch: fix leak when checking against HEAD
We look up a reference in order to figure out if it's the current branch, which we need to free once we're done with the check. As a bonus, only perform the check when we're passed the force flag, as it's a useless check otherwise.
This commit is contained in:
parent
7c1ee212b7
commit
a07b169834
16
src/branch.c
16
src/branch.c
@ -66,16 +66,22 @@ int git_branch_create(
|
|||||||
|
|
||||||
assert(branch_name && commit && ref_out);
|
assert(branch_name && commit && ref_out);
|
||||||
assert(git_object_owner((const git_object *)commit) == repository);
|
assert(git_object_owner((const git_object *)commit) == repository);
|
||||||
if (git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
|
|
||||||
if ((is_head = git_branch_is_head(branch)) < 0) {
|
if (force && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
|
||||||
error = is_head;
|
error = git_branch_is_head(branch);
|
||||||
|
git_reference_free(branch);
|
||||||
|
branch = NULL;
|
||||||
|
|
||||||
|
if (error < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
is_head = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_head && force) {
|
if (is_head && force) {
|
||||||
giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
|
giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
|
||||||
"the current HEAD of the repository.", git_reference_name(branch));
|
"the current HEAD of the repository.", branch_name);
|
||||||
|
error = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user