[libvirt] [PATCH 12/22] qemu: monitor: Refactor cleanup in qemuMonitorJSONGetAllBlockStatsInfo

Peter Krempa pkrempa at redhat.com
Thu Sep 19 17:13:15 UTC 2019


Use VIR_AUTOPTR and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_monitor_json.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8d0ef62c8b..9be122a465 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2678,11 +2678,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
                                     virHashTablePtr hash,
                                     bool backingChain)
 {
-    int ret = -1;
     int nstats = 0;
     int rc;
     size_t i;
-    virJSONValuePtr devices;
+    VIR_AUTOPTR(virJSONValue) devices = NULL;

     if (!(devices = qemuMonitorJSONQueryBlockstats(mon)))
         return -1;
@@ -2695,14 +2694,14 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("blockstats device entry was not "
                              "in expected format"));
-            goto cleanup;
+            return -1;
         }

         if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("blockstats device entry was not "
                              "in expected format"));
-            goto cleanup;
+            return -1;
         }

         if (*dev_name == '\0')
@@ -2712,17 +2711,13 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
                                                  backingChain);

         if (rc < 0)
-            goto cleanup;
+            return -1;

         if (rc > nstats)
             nstats = rc;
     }

-    ret = nstats;
-
- cleanup:
-    virJSONValueFree(devices);
-    return ret;
+    return nstats;
 }


-- 
2.21.0




More information about the libvir-list mailing list