[libvirt PATCH 3/4] qemu: tpm: use g_autoptr where applicable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This requires stealing one cmd pointer before returning it.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/qemu/qemu_tpm.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index cfe7eb1846..f9cea2ffde 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -425,7 +425,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
                         const unsigned char *secretuuid,
                         bool incomingMigration)
 {
-    virCommandPtr cmd = NULL;
+    g_autoptr(virCommand) cmd = NULL;
     int exitstatus;
     int ret = -1;
     char uuid[VIR_UUID_STRING_BUFLEN];
@@ -512,8 +512,6 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
     ret = 0;
 
  cleanup:
-    virCommandFree(cmd);
-
     return ret;
 }
 
@@ -547,7 +545,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm,
                             const char *shortName,
                             bool incomingMigration)
 {
-    virCommandPtr cmd = NULL;
+    g_autoptr(virCommand) cmd = NULL;
     bool created = false;
     g_autofree char *pidfile = NULL;
     g_autofree char *swtpm = virTPMGetSwtpm();
@@ -639,14 +637,12 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm,
         migpwdfile_fd = -1;
     }
 
-    return cmd;
+    return g_steal_pointer(&cmd);
 
  error:
     if (created)
         qemuTPMDeleteEmulatorStorage(tpm);
 
-    virCommandFree(cmd);
-
     return NULL;
 }
 
@@ -703,7 +699,7 @@ int
 qemuExtTPMInitPaths(virQEMUDriverPtr driver,
                     virDomainDefPtr def)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     int ret = 0;
 
     switch (def->tpm->type) {
@@ -716,8 +712,6 @@ qemuExtTPMInitPaths(virQEMUDriverPtr driver,
         break;
     }
 
-    virObjectUnref(cfg);
-
     return ret;
 }
 
@@ -726,7 +720,7 @@ int
 qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
                       virDomainDefPtr def)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     int ret = 0;
     g_autofree char *shortName = NULL;
 
@@ -748,8 +742,6 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
     }
 
  cleanup:
-    virObjectUnref(cfg);
-
     return ret;
 }
 
@@ -876,7 +868,7 @@ void
 qemuExtTPMStop(virQEMUDriverPtr driver,
                virDomainObjPtr vm)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     g_autofree char *shortName = NULL;
 
     switch (vm->def->tpm->type) {
@@ -894,7 +886,7 @@ qemuExtTPMStop(virQEMUDriverPtr driver,
     }
 
  cleanup:
-    virObjectUnref(cfg);
+    return;
 }
 
 
@@ -903,7 +895,7 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
                       virDomainDefPtr def,
                       virCgroupPtr cgroup)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     g_autofree char *shortName = NULL;
     int ret = -1, rc;
     pid_t pid;
@@ -930,7 +922,5 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
     ret = 0;
 
  cleanup:
-    virObjectUnref(cfg);
-
     return ret;
 }
-- 
2.19.2





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux