]> xenbits.xensource.com Git - libvirt.git/commitdiff
driver: Don't leak saved error in virGetConnectGeneric()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 17 May 2021 12:48:36 +0000 (14:48 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 17 May 2021 13:53:39 +0000 (15:53 +0200)
Recently, a new code was added to virGetConnectGeneric() that
saves the original error into a variable so that it's not lost in
virConnectClose() called under the 'error' label.

However, the error saving code uses virSaveLastError() +
virSetError() combo which leaks the memory allocated for the
error copy. Using virErrorPreserveLast() + virErrorRestore() does
the same job without the memleak.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/driver.c

index 227bb56e48f7c435d0c36492b21dcc0856d3db77..329d493a50035bc169b5c0171602ec47981949d2 100644 (file)
@@ -138,7 +138,7 @@ static virConnectPtr
 virGetConnectGeneric(virThreadLocal *threadPtr, const char *name)
 {
     virConnectPtr conn;
-    virErrorPtr saved;
+    virErrorPtr orig_err;
 
     if (virConnectCacheInitialize() < 0)
         return NULL;
@@ -178,9 +178,9 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const char *name)
     return conn;
 
  error:
-    saved = virSaveLastError();
+    virErrorPreserveLast(&orig_err);
     virConnectClose(conn);
-    virSetError(saved);
+    virErrorRestore(&orig_err);
     return NULL;
 }