render / rpms / libvirt

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