mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-21 22:21:37 +00:00
refs: fix leak on successful update
Free the old ref even on success.
This commit is contained in:
parent
fc4728e3e2
commit
1202c7eaa6
@ -941,7 +941,7 @@ static int refdb_fs_backend__write(
|
|||||||
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
|
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
|
||||||
git_filebuf file = GIT_FILEBUF_INIT;
|
git_filebuf file = GIT_FILEBUF_INIT;
|
||||||
git_reference *old_ref;
|
git_reference *old_ref;
|
||||||
int error = 0;
|
int error = 0, cmp;
|
||||||
|
|
||||||
assert(backend);
|
assert(backend);
|
||||||
|
|
||||||
@ -954,19 +954,20 @@ static int refdb_fs_backend__write(
|
|||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (old_id) {
|
if (old_id) {
|
||||||
if ((error = refdb_fs_backend__lookup(&old_ref, _backend, ref->name)) < 0) {
|
if ((error = refdb_fs_backend__lookup(&old_ref, _backend, ref->name)) < 0)
|
||||||
git_filebuf_cleanup(&file);
|
goto on_error;
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (old_ref->type == GIT_REF_SYMBOLIC) {
|
if (old_ref->type == GIT_REF_SYMBOLIC) {
|
||||||
|
git_reference_free(old_ref);
|
||||||
giterr_set(GITERR_REFERENCE, "cannot compare id to symbolic reference target");
|
giterr_set(GITERR_REFERENCE, "cannot compare id to symbolic reference target");
|
||||||
error = -1;
|
error = -1;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally we can compare the ids */
|
/* Finally we can compare the ids */
|
||||||
if (git_oid_cmp(old_id, &old_ref->target.oid)) {
|
cmp = git_oid_cmp(old_id, &old_ref->target.oid);
|
||||||
|
git_reference_free(old_ref);
|
||||||
|
if (cmp) {
|
||||||
giterr_set(GITERR_REFERENCE, "old reference value does not match");
|
giterr_set(GITERR_REFERENCE, "old reference value does not match");
|
||||||
error = GIT_EMODIFIED;
|
error = GIT_EMODIFIED;
|
||||||
goto on_error;
|
goto on_error;
|
||||||
@ -983,7 +984,6 @@ static int refdb_fs_backend__write(
|
|||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
git_filebuf_cleanup(&file);
|
git_filebuf_cleanup(&file);
|
||||||
git_reference_free(old_ref);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user