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