[libvirt PATCH 2/4] util: virIdentitySetCurrent: only unref the old identity on success

Ján Tomko jtomko at redhat.com
Sat Sep 4 19:25:47 UTC 2021


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 at redhat.com>
---
 src/util/viridentity.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/viridentity.c b/src/util/viridentity.c
index e36e54ae4b..70843ecf9f 100644
--- a/src/util/viridentity.c
+++ b/src/util/viridentity.c
@@ -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;
 }
 
-- 
2.31.1




More information about the libvir-list mailing list