mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
viridentity: Fix ref/unref imbalance in VIR_IDENTITY_AUTORESTORE
The basic use case of VIR_IDENTITY_AUTORESTORE() is in conjunction with virIdentityElevateCurrent(). What happens is that virIdentityElevateCurrent() gets current identity (which increases the refcounter of thread local virIdentity object) and returns a pointer to it. Later, when the variable goes out of scope the virIdentityRestoreHelper() is called which calls virIdentitySetCurrent() over the old identity. But this means that the refcounter is increased again. Therefore, we have to explicitly decrease the refcounter by calling g_object_unref(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
b24a45827a
commit
530715bd0b
@ -197,8 +197,12 @@ void virIdentityRestoreHelper(virIdentity **identptr)
|
||||
{
|
||||
virIdentity *ident = *identptr;
|
||||
|
||||
if (ident != NULL)
|
||||
if (ident != NULL) {
|
||||
virIdentitySetCurrent(ident);
|
||||
/* virIdentitySetCurrent() grabs its own reference.
|
||||
* We don't need ours anymore. */
|
||||
g_object_unref(ident);
|
||||
}
|
||||
}
|
||||
|
||||
#define TOKEN_BYTES 16
|
||||
|
Loading…
Reference in New Issue
Block a user