[PATCH 5/8] qemuDomainGetStatsBlock: Refactor cleanup

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

 



Use automatic memory clearing for the temporary variables and remove the
cleanup section.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b46ee01d31..822fd99ae2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18461,11 +18461,10 @@ qemuDomainGetStatsBlock(virQEMUDriver *driver,
                         unsigned int privflags)
 {
     size_t i;
-    int ret = -1;
     int rc;
-    GHashTable *stats = NULL;
-    GHashTable *nodestats = NULL;
-    virJSONValue *nodedata = NULL;
+    g_autoptr(GHashTable) stats = NULL;
+    g_autoptr(GHashTable) nodestats = NULL;
+    g_autoptr(virJSONValue) nodedata = NULL;
     qemuDomainObjPrivate *priv = dom->privateData;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
@@ -18492,7 +18491,7 @@ qemuDomainGetStatsBlock(virQEMUDriver *driver,
             nodedata = qemuMonitorQueryNamedBlockNodes(priv->mon);

         if (qemuDomainObjExitMonitor(driver, dom) < 0)
-            goto cleanup;
+            return -1;

         /* failure to retrieve stats is fine at this point */
         if (rc < 0 || (fetchnodedata && !nodedata))
@@ -18501,31 +18500,26 @@ qemuDomainGetStatsBlock(virQEMUDriver *driver,

     if (nodedata &&
         !(nodestats = qemuBlockGetNodeData(nodedata)))
-        goto cleanup;
+        return -1;

     /* When listing backing chains, it's easier to fix up the count
      * after the iteration than it is to iterate twice; but we still
      * want count listed first.  */
     count_index = params->npar;
     if (virTypedParamListAddUInt(params, 0, "block.count") < 0)
-        goto cleanup;
+        return -1;

     for (i = 0; i < dom->def->ndisks; i++) {
         if (qemuDomainGetStatsBlockExportDisk(dom->def->disks[i], stats, nodestats,
                                               params, &visited,
                                               visitBacking, driver, cfg, dom,
                                               blockdev) < 0)
-            goto cleanup;
+            return -1;
     }

     params->par[count_index].value.ui = visited;
-    ret = 0;

- cleanup:
-    virHashFree(stats);
-    virHashFree(nodestats);
-    virJSONValueFree(nodedata);
-    return ret;
+    return 0;
 }


-- 
2.31.1




[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