]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virIdentitySetCurrent: only unref the old identity on success
authorJán Tomko <jtomko@redhat.com>
Fri, 3 Sep 2021 14:04:44 +0000 (16:04 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 8 Sep 2021 14:19:55 +0000 (16:19 +0200)
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: c6825d88137cb8e4debdf4310e45ee23cb5698c0
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/viridentity.c

index e36e54ae4b9abc1d00246f68692261daee330508..70843ecf9f3a5b5e5bf0bb02335cfa4f5428d8d7 100644 (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;
 }