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>
{
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