From: Ján Tomko Date: Fri, 3 Sep 2021 14:04:44 +0000 (+0200) Subject: util: virIdentitySetCurrent: only unref the old identity on success X-Git-Tag: v7.8.0-rc1~308 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a082c462290bfa8fd4cbbc41c1d6040864228c78;p=thirdparty%2Flibvirt.git 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: c6825d88137cb8e4debdf4310e45ee23cb5698c0 Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- 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; }