mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: identity: Harden virIdentitySetCurrent()
Don't unref the old identity unless we set the new one correctly and unref the new one on failure to set it so that we don't leak any references or use invalid pointers. (cherry picked from commit ad886fa6c8ebc321a0386a75c187d315111cf1f3)
This commit is contained in:
parent
dc7c0de587
commit
5081142ed8
@ -111,15 +111,17 @@ int virIdentitySetCurrent(virIdentityPtr ident)
|
||||
return -1;
|
||||
|
||||
old = virThreadLocalGet(&virIdentityCurrent);
|
||||
virObjectUnref(old);
|
||||
|
||||
if (virThreadLocalSet(&virIdentityCurrent,
|
||||
virObjectRef(ident)) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to set thread local identity"));
|
||||
virObjectUnref(ident);
|
||||
return -1;
|
||||
}
|
||||
|
||||
virObjectUnref(old);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user