fbe740
From bcc3726dae87335a533565c6d679434fa69fe75e Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <bcc3726dae87335a533565c6d679434fa69fe75e@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:11:41 +0100
fbe740
Subject: [PATCH] qemu: Don't take double pointer in qemuDomainSecretInfoFree
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Using a double pointer prevents the function from being used as the
fbe740
automatic cleanup function for the given type.
fbe740
fbe740
Remove the double pointer use by replacing the calls with
fbe740
g_clear_pointer which ensures that the pointer is cleared.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 38bc76bcc1e1bccb7f3265e15b60b0f6f8fe6dfa)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
fbe740
Message-Id: <56ebeda94754aab81a682202f26c1dc158ac063a.1584391726.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_domain.c           | 30 +++++++++++++-----------------
fbe740
 src/qemu/qemu_domain.h           |  2 +-
fbe740
 src/qemu/qemu_migration_params.c |  2 +-
fbe740
 3 files changed, 15 insertions(+), 19 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
fbe740
index 14bab896bc..b77488026a 100644
fbe740
--- a/src/qemu/qemu_domain.c
fbe740
+++ b/src/qemu/qemu_domain.c
fbe740
@@ -1106,14 +1106,10 @@ qemuDomainSecretInfoClear(qemuDomainSecretInfoPtr secinfo,
fbe740
 
fbe740
 
fbe740
 void
fbe740
-qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
fbe740
+qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr secinfo)
fbe740
 {
fbe740
-    if (!*secinfo)
fbe740
-        return;
fbe740
-
fbe740
-    qemuDomainSecretInfoClear(*secinfo, false);
fbe740
-
fbe740
-    VIR_FREE(*secinfo);
fbe740
+    qemuDomainSecretInfoClear(secinfo, false);
fbe740
+    g_free(secinfo);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -1203,8 +1199,8 @@ qemuDomainStorageSourcePrivateDispose(void *obj)
fbe740
 {
fbe740
     qemuDomainStorageSourcePrivatePtr priv = obj;
fbe740
 
fbe740
-    qemuDomainSecretInfoFree(&priv->secinfo);
fbe740
-    qemuDomainSecretInfoFree(&priv->encinfo);
fbe740
+    g_clear_pointer(&priv->secinfo, qemuDomainSecretInfoFree);
fbe740
+    g_clear_pointer(&priv->encinfo, qemuDomainSecretInfoFree);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -1283,7 +1279,7 @@ qemuDomainChrSourcePrivateDispose(void *obj)
fbe740
 {
fbe740
     qemuDomainChrSourcePrivatePtr priv = obj;
fbe740
 
fbe740
-    qemuDomainSecretInfoFree(&priv->secinfo);
fbe740
+    g_clear_pointer(&priv->secinfo, qemuDomainSecretInfoFree);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -1362,7 +1358,7 @@ qemuDomainGraphicsPrivateDispose(void *obj)
fbe740
     qemuDomainGraphicsPrivatePtr priv = obj;
fbe740
 
fbe740
     VIR_FREE(priv->tlsAlias);
fbe740
-    qemuDomainSecretInfoFree(&priv->secinfo);
fbe740
+    g_clear_pointer(&priv->secinfo, qemuDomainSecretInfoFree);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -1642,7 +1638,7 @@ qemuDomainSecretInfoNewPlain(virSecretUsageType usageType,
fbe740
         return NULL;
fbe740
 
fbe740
     if (qemuDomainSecretPlainSetup(secinfo, usageType, username, lookupDef) < 0) {
fbe740
-        qemuDomainSecretInfoFree(&secinfo);
fbe740
+        g_clear_pointer(&secinfo, qemuDomainSecretInfoFree);
fbe740
         return NULL;
fbe740
     }
fbe740
 
fbe740
@@ -1685,7 +1681,7 @@ qemuDomainSecretInfoNew(qemuDomainObjPrivatePtr priv,
fbe740
 
fbe740
     if (qemuDomainSecretAESSetup(priv, secinfo, srcAlias, usageType, username,
fbe740
                                  lookupDef, isLuks) < 0) {
fbe740
-        qemuDomainSecretInfoFree(&secinfo);
fbe740
+        g_clear_pointer(&secinfo, qemuDomainSecretInfoFree);
fbe740
         return NULL;
fbe740
     }
fbe740
 
fbe740
@@ -1847,7 +1843,7 @@ qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr hostdev)
fbe740
         if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
fbe740
             srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(iscsisrc->src);
fbe740
             if (srcPriv && srcPriv->secinfo)
fbe740
-                qemuDomainSecretInfoFree(&srcPriv->secinfo);
fbe740
+                g_clear_pointer(&srcPriv->secinfo, qemuDomainSecretInfoFree);
fbe740
         }
fbe740
     }
fbe740
 }
fbe740
@@ -1891,7 +1887,7 @@ qemuDomainSecretChardevDestroy(virDomainChrSourceDefPtr dev)
fbe740
     if (!chrSourcePriv || !chrSourcePriv->secinfo)
fbe740
         return;
fbe740
 
fbe740
-    qemuDomainSecretInfoFree(&chrSourcePriv->secinfo);
fbe740
+    g_clear_pointer(&chrSourcePriv->secinfo, qemuDomainSecretInfoFree);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -1947,7 +1943,7 @@ qemuDomainSecretGraphicsDestroy(virDomainGraphicsDefPtr graphics)
fbe740
         return;
fbe740
 
fbe740
     VIR_FREE(gfxPriv->tlsAlias);
fbe740
-    qemuDomainSecretInfoFree(&gfxPriv->secinfo);
fbe740
+    g_clear_pointer(&gfxPriv->secinfo, qemuDomainSecretInfoFree);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -2307,7 +2303,7 @@ qemuDomainObjPrivateFree(void *data)
fbe740
     }
fbe740
     VIR_FREE(priv->cleanupCallbacks);
fbe740
 
fbe740
-    qemuDomainSecretInfoFree(&priv->migSecinfo);
fbe740
+    g_clear_pointer(&priv->migSecinfo, qemuDomainSecretInfoFree);
fbe740
     qemuDomainMasterKeyFree(priv);
fbe740
 
fbe740
     virHashFree(priv->blockjobs);
fbe740
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
fbe740
index 9d143b575d..89a967efd7 100644
fbe740
--- a/src/qemu/qemu_domain.h
fbe740
+++ b/src/qemu/qemu_domain.h
fbe740
@@ -1032,7 +1032,7 @@ void qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv);
fbe740
 
fbe740
 bool qemuDomainSupportsEncryptedSecret(qemuDomainObjPrivatePtr priv);
fbe740
 
fbe740
-void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr *secinfo)
fbe740
+void qemuDomainSecretInfoFree(qemuDomainSecretInfoPtr secinfo)
fbe740
     ATTRIBUTE_NONNULL(1);
fbe740
 
fbe740
 void qemuDomainSecretInfoDestroy(qemuDomainSecretInfoPtr secinfo);
fbe740
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
fbe740
index 45acf8cda2..f61796713f 100644
fbe740
--- a/src/qemu/qemu_migration_params.c
fbe740
+++ b/src/qemu/qemu_migration_params.c
fbe740
@@ -1090,7 +1090,7 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
fbe740
     secAlias = qemuDomainGetSecretAESAlias(QEMU_MIGRATION_TLS_ALIAS_BASE, false);
fbe740
 
fbe740
     qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, tlsAlias);
fbe740
-    qemuDomainSecretInfoFree(&QEMU_DOMAIN_PRIVATE(vm)->migSecinfo);
fbe740
+    g_clear_pointer(&QEMU_DOMAIN_PRIVATE(vm)->migSecinfo, qemuDomainSecretInfoFree);
fbe740
 
fbe740
     VIR_FREE(tlsAlias);
fbe740
     VIR_FREE(secAlias);
fbe740
-- 
fbe740
2.25.1
fbe740