util: virIdentitySetCurrent: only unref the old identity on success

In the unlikely case that we were unable to set the new
identity, we would unref the old one even though it still
could be in the thread-local storage.

Fixes: c6825d8813
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2021-09-03 16:04:44 +02:00
parent 09b08e9a80
commit a082c46229

View File

@ -134,7 +134,7 @@ virIdentity *virIdentityGetCurrent(void)
*/
int virIdentitySetCurrent(virIdentity *ident)
{
g_autoptr(virIdentity) old = NULL;
virIdentity *old = NULL;
if (virIdentityInitialize() < 0)
return -1;
@ -150,6 +150,8 @@ int virIdentitySetCurrent(virIdentity *ident)
return -1;
}
if (old)
g_object_unref(old);
return 0;
}