[PATCH v2 5/9] qemu_driver: use VIR_AUTOUNREF() with more pointer types

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

 



This patch uses VIR_AUTOUNREF() with the following pointer types:

- virQEMUCapsPtr
- virConnect
- qemuDomainSaveCookiePtr
- virDomainCapsPtr
- qemuBlockJobDataPtr*
- virNetworkPtr
- virSecurityManagerPtr

'cleanup' labels were deleted when possible.

* instances being cleaned up with qemuBlockJobStartupFinalize()
weren't changed, since qemuBlockJobStartupFinalize() will
unref the object after qemuBlockJobUnregister().

Suggested-by: Erik Skultety <eskultet@xxxxxxxxxx>
Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_driver.c | 76 +++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 49 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9958164788..48eca00777 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -305,8 +305,8 @@ static int
 qemuSecurityInit(virQEMUDriverPtr driver)
 {
     char **names;
-    virSecurityManagerPtr mgr = NULL;
-    virSecurityManagerPtr stack = NULL;
+    VIR_AUTOUNREF(virSecurityManagerPtr) mgr = NULL;
+    VIR_AUTOUNREF(virSecurityManagerPtr) stack = NULL;
     VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
     unsigned int flags = 0;
 
@@ -372,8 +372,6 @@ qemuSecurityInit(virQEMUDriverPtr driver)
  error:
     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                    _("Failed to initialize security drivers"));
-    virObjectUnref(stack);
-    virObjectUnref(mgr);
     return -1;
 }
 
@@ -1093,7 +1091,7 @@ static int
 qemuStateStop(void)
 {
     int ret = -1;
-    virConnectPtr conn;
+    VIR_AUTOUNREF(virConnectPtr) conn = NULL;
     int numDomains = 0;
     size_t i;
     int state;
@@ -1137,7 +1135,6 @@ qemuStateStop(void)
         VIR_FREE(domains);
     }
     VIR_FREE(flags);
-    virObjectUnref(conn);
 
     return ret;
 }
@@ -3305,7 +3302,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     VIR_AUTOUNREF(virCapsPtr) caps = NULL;
     virQEMUSaveDataPtr data = NULL;
-    qemuDomainSaveCookiePtr cookie = NULL;
+    VIR_AUTOUNREF(qemuDomainSaveCookiePtr) cookie = NULL;
 
     if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
         goto cleanup;
@@ -3414,7 +3411,6 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
         qemuDomainRemoveInactiveJob(driver, vm);
 
  cleanup:
-    virObjectUnref(cookie);
     VIR_FREE(xml);
     virQEMUSaveDataFree(data);
     virObjectEventStateQueue(driver->domainEventState, event);
@@ -6861,7 +6857,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
     char *errbuf = NULL;
     VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
     virQEMUSaveHeaderPtr header = &data->header;
-    qemuDomainSaveCookiePtr cookie = NULL;
+    VIR_AUTOUNREF(qemuDomainSaveCookiePtr) cookie = NULL;
 
     if (virSaveCookieParseString(data->cookie, (virObjectPtr *)&cookie,
                                  virDomainXMLOptionGetSaveCookie(driver->xmlopt)) < 0)
@@ -6976,7 +6972,6 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
     ret = 0;
 
  cleanup:
-    virObjectUnref(cookie);
     virCommandFree(cmd);
     VIR_FREE(errbuf);
     if (qemuSecurityRestoreSavedStateLabel(driver, vm, path) < 0)
@@ -13533,9 +13528,8 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
                                 const char *xmlCPU,
                                 unsigned int flags)
 {
-    int ret = VIR_CPU_COMPARE_ERROR;
     virQEMUDriverPtr driver = conn->privateData;
-    virQEMUCapsPtr qemuCaps = NULL;
+    VIR_AUTOUNREF(virQEMUCapsPtr) qemuCaps = NULL;
     bool failIncompatible;
     virCPUDefPtr hvCPU;
     virArch arch;
@@ -13545,7 +13539,7 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
                   VIR_CPU_COMPARE_ERROR);
 
     if (virConnectCompareHypervisorCPUEnsureACL(conn) < 0)
-        goto cleanup;
+        return VIR_CPU_COMPARE_ERROR;
 
     failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
 
@@ -13556,7 +13550,7 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
                                              machine,
                                              &arch, &virttype, NULL);
     if (!qemuCaps)
-        goto cleanup;
+        return VIR_CPU_COMPARE_ERROR;
 
     hvCPU = virQEMUCapsGetHostModel(qemuCaps, virttype,
                                     VIR_QEMU_CAPS_HOST_CPU_REPORTED);
@@ -13567,20 +13561,18 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
                          "virttype '%s'"),
                        virQEMUCapsGetBinary(qemuCaps),
                        virDomainVirtTypeToString(virttype));
-        goto cleanup;
+        return VIR_CPU_COMPARE_ERROR;
     }
 
     if (ARCH_IS_X86(arch)) {
-        ret = virCPUCompareXML(arch, hvCPU, xmlCPU, failIncompatible);
+        return virCPUCompareXML(arch, hvCPU, xmlCPU, failIncompatible);
     } else {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("comparing with the hypervisor CPU is not supported "
                          "for arch %s"), virArchToString(arch));
     }
 
- cleanup:
-    virObjectUnref(qemuCaps);
-    return ret;
+    return VIR_CPU_COMPARE_ERROR;
 }
 
 
@@ -13643,7 +13635,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
 {
     virQEMUDriverPtr driver = conn->privateData;
     virCPUDefPtr *cpus = NULL;
-    virQEMUCapsPtr qemuCaps = NULL;
+    VIR_AUTOUNREF(virQEMUCapsPtr) qemuCaps = NULL;
     virArch arch;
     virDomainVirtType virttype;
     virDomainCapsCPUModelsPtr cpuModels;
@@ -13714,7 +13706,6 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
  cleanup:
     virCPUDefListFree(cpus);
     virCPUDefFree(cpu);
-    virObjectUnref(qemuCaps);
     virStringListFree(features);
 
     return cpustr;
@@ -17541,7 +17532,7 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
     VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
     bool pivot = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT);
     bool async = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC);
-    qemuBlockJobDataPtr job = NULL;
+    VIR_AUTOUNREF(qemuBlockJobDataPtr) job = NULL;
     virDomainObjPtr vm;
     qemuDomainObjPrivatePtr priv = NULL;
     bool blockdev = false;
@@ -17642,7 +17633,6 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-    virObjectUnref(job);
     virDomainObjEndAPI(&vm);
     return ret;
 }
@@ -20312,17 +20302,16 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
                                  const char *virttype_str,
                                  unsigned int flags)
 {
-    char *ret = NULL;
     virQEMUDriverPtr driver = conn->privateData;
-    virQEMUCapsPtr qemuCaps = NULL;
+    VIR_AUTOUNREF(virQEMUCapsPtr) qemuCaps = NULL;
     virArch arch;
     virDomainVirtType virttype;
-    virDomainCapsPtr domCaps = NULL;
+    VIR_AUTOUNREF(virDomainCapsPtr) domCaps = NULL;
 
-    virCheckFlags(0, ret);
+    virCheckFlags(0, NULL);
 
     if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
-        return ret;
+        return NULL;
 
     qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache,
                                              emulatorbin,
@@ -20331,18 +20320,14 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
                                              machine,
                                              &arch, &virttype, &machine);
     if (!qemuCaps)
-        goto cleanup;
+        return NULL;
 
     if (!(domCaps = virQEMUDriverGetDomainCapabilities(driver,
                                                        qemuCaps, machine,
                                                        arch, virttype)))
-        goto cleanup;
+        return NULL;
 
-    ret = virDomainCapsFormat(domCaps);
- cleanup:
-    virObjectUnref(domCaps);
-    virObjectUnref(qemuCaps);
-    return ret;
+    return virDomainCapsFormat(domCaps);
 }
 
 
@@ -21585,7 +21570,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
     int n_leases = 0;
     size_t i, j;
     size_t ifaces_count = 0;
-    virNetworkPtr network = NULL;
+    VIR_AUTOUNREF(virNetworkPtr) network = NULL;
     char macaddr[VIR_MAC_STRING_BUFLEN];
     virDomainInterfacePtr iface = NULL;
     virNetworkDHCPLeasePtr *leases = NULL;
@@ -21653,7 +21638,6 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
     rv = ifaces_count;
 
  cleanup:
-    virObjectUnref(network);
     if (leases) {
         for (i = 0; i < n_leases; i++)
             virNetworkDHCPLeaseFree(leases[i]);
@@ -22448,32 +22432,26 @@ qemuNodeGetSEVInfo(virConnectPtr conn,
                    unsigned int flags)
 {
     virQEMUDriverPtr driver = conn->privateData;
-    virQEMUCapsPtr qemucaps = NULL;
-    int ret = -1;
+    VIR_AUTOUNREF(virQEMUCapsPtr) qemucaps = NULL;
 
     if (virNodeGetSevInfoEnsureACL(conn) < 0)
-        return ret;
+        return -1;
 
     qemucaps = virQEMUCapsCacheLookupByArch(driver->qemuCapsCache,
                                             virArchFromHost());
     if (!qemucaps)
-        goto cleanup;
+        return -1;
 
     if (!virQEMUCapsGet(qemucaps, QEMU_CAPS_SEV_GUEST)) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
                        _("QEMU does not support SEV guest"));
-        goto cleanup;
+        return -1;
     }
 
     if (qemuGetSEVInfoToParams(qemucaps, params, nparams, flags) < 0)
-        goto cleanup;
-
-    ret = 0;
-
- cleanup:
-    virObjectUnref(qemucaps);
+        return -1;
 
-    return ret;
+    return 0;
 }
 
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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