fbe740
From c5cdebd40024c33675f93b47732869c658204056 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <c5cdebd40024c33675f93b47732869c658204056@dist-git>
fbe740
From: Michal Privoznik <mprivozn@redhat.com>
fbe740
Date: Thu, 16 Jan 2020 10:03:53 +0100
fbe740
Subject: [PATCH] qemu: Use g_autoptr() for qemuDomainSaveCookie
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
fbe740
fbe740
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1718707
fbe740
fbe740
(cherry picked from commit 3203ad6cfd617fb11d4bb47e514c370b6624641b)
fbe740
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
Message-Id: <5e58b5853f9bd1a2b5109145afdad190071f5c44.1579165329.git.mprivozn@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_domain.c | 28 ++++++++++------------------
fbe740
 src/qemu/qemu_domain.h |  1 +
fbe740
 src/qemu/qemu_driver.c |  6 ++----
fbe740
 3 files changed, 13 insertions(+), 22 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
fbe740
index 0edf316fff..91a9f0481b 100644
fbe740
--- a/src/qemu/qemu_domain.c
fbe740
+++ b/src/qemu/qemu_domain.c
fbe740
@@ -16001,27 +16001,23 @@ qemuDomainSaveCookiePtr
fbe740
 qemuDomainSaveCookieNew(virDomainObjPtr vm)
fbe740
 {
fbe740
     qemuDomainObjPrivatePtr priv = vm->privateData;
fbe740
-    qemuDomainSaveCookiePtr cookie = NULL;
fbe740
+    g_autoptr(qemuDomainSaveCookie) cookie = NULL;
fbe740
 
fbe740
     if (qemuDomainInitialize() < 0)
fbe740
-        goto error;
fbe740
+        return NULL;
fbe740
 
fbe740
     if (!(cookie = virObjectNew(qemuDomainSaveCookieClass)))
fbe740
-        goto error;
fbe740
+        return NULL;
fbe740
 
fbe740
     if (priv->origCPU && !(cookie->cpu = virCPUDefCopy(vm->def->cpu)))
fbe740
-        goto error;
fbe740
+        return NULL;
fbe740
 
fbe740
     cookie->slirpHelper = qemuDomainGetSlirpHelperOk(vm);
fbe740
 
fbe740
     VIR_DEBUG("Save cookie %p, cpu=%p, slirpHelper=%d",
fbe740
               cookie, cookie->cpu, cookie->slirpHelper);
fbe740
 
fbe740
-    return cookie;
fbe740
-
fbe740
- error:
fbe740
-    virObjectUnref(cookie);
fbe740
-    return NULL;
fbe740
+    return g_steal_pointer(&cookie);
fbe740
 }
fbe740
 
fbe740
 
fbe740
@@ -16029,26 +16025,22 @@ static int
fbe740
 qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt G_GNUC_UNUSED,
fbe740
                           virObjectPtr *obj)
fbe740
 {
fbe740
-    qemuDomainSaveCookiePtr cookie = NULL;
fbe740
+    g_autoptr(qemuDomainSaveCookie) cookie = NULL;
fbe740
 
fbe740
     if (qemuDomainInitialize() < 0)
fbe740
-        goto error;
fbe740
+        return -1;
fbe740
 
fbe740
     if (!(cookie = virObjectNew(qemuDomainSaveCookieClass)))
fbe740
-        goto error;
fbe740
+        return -1;
fbe740
 
fbe740
     if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST,
fbe740
                           &cookie->cpu) < 0)
fbe740
-        goto error;
fbe740
+        return -1;
fbe740
 
fbe740
     cookie->slirpHelper = virXPathBoolean("boolean(./slirpHelper)", ctxt) > 0;
fbe740
 
fbe740
-    *obj = (virObjectPtr) cookie;
fbe740
+    *obj = (virObjectPtr) g_steal_pointer(&cookie);
fbe740
     return 0;
fbe740
-
fbe740
- error:
fbe740
-    virObjectUnref(cookie);
fbe740
-    return -1;
fbe740
 }
fbe740
 
fbe740
 
fbe740
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
fbe740
index c6afc484f6..60b80297fa 100644
fbe740
--- a/src/qemu/qemu_domain.h
fbe740
+++ b/src/qemu/qemu_domain.h
fbe740
@@ -610,6 +610,7 @@ struct _qemuDomainSaveCookie {
fbe740
     bool slirpHelper;
fbe740
 };
fbe740
 
fbe740
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuDomainSaveCookie, virObjectUnref);
fbe740
 
fbe740
 typedef struct _qemuDomainXmlNsDef qemuDomainXmlNsDef;
fbe740
 typedef qemuDomainXmlNsDef *qemuDomainXmlNsDefPtr;
fbe740
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
fbe740
index e1c0550b9a..ce9b1772c1 100644
fbe740
--- a/src/qemu/qemu_driver.c
fbe740
+++ b/src/qemu/qemu_driver.c
fbe740
@@ -3293,7 +3293,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
fbe740
     virObjectEventPtr event = NULL;
fbe740
     qemuDomainObjPrivatePtr priv = vm->privateData;
fbe740
     virQEMUSaveDataPtr data = NULL;
fbe740
-    qemuDomainSaveCookiePtr cookie = NULL;
fbe740
+    g_autoptr(qemuDomainSaveCookie) cookie = NULL;
fbe740
 
fbe740
     if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
fbe740
         goto cleanup;
fbe740
@@ -3399,7 +3399,6 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
fbe740
         qemuDomainRemoveInactiveJob(driver, vm);
fbe740
 
fbe740
  cleanup:
fbe740
-    virObjectUnref(cookie);
fbe740
     virQEMUSaveDataFree(data);
fbe740
     virObjectEventStateQueue(driver->domainEventState, event);
fbe740
     return ret;
fbe740
@@ -6808,7 +6807,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
fbe740
     g_autofree char *errbuf = NULL;
fbe740
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
fbe740
     virQEMUSaveHeaderPtr header = &data->header;
fbe740
-    qemuDomainSaveCookiePtr cookie = NULL;
fbe740
+    g_autoptr(qemuDomainSaveCookie) cookie = NULL;
fbe740
 
fbe740
     if (virSaveCookieParseString(data->cookie, (virObjectPtr *)&cookie,
fbe740
                                  virDomainXMLOptionGetSaveCookie(driver->xmlopt)) < 0)
fbe740
@@ -6919,7 +6918,6 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
fbe740
     ret = 0;
fbe740
 
fbe740
  cleanup:
fbe740
-    virObjectUnref(cookie);
fbe740
     if (qemuSecurityRestoreSavedStateLabel(driver, vm, path) < 0)
fbe740
         VIR_WARN("failed to restore save state label on %s", path);
fbe740
     return ret;
fbe740
-- 
fbe740
2.25.0
fbe740