[libvirt] [PATCH 10/22] qemu: monitor: Refactor cleanup in qemuMonitorJSONBlockStatsCollectData

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


Use VIR_AUTOFREE 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 e4404f0199..ccf9290838 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2529,8 +2529,7 @@ static qemuBlockStatsPtr
 qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev,
                                      int *nstats)
 {
-    qemuBlockStatsPtr bstats = NULL;
-    qemuBlockStatsPtr ret = NULL;
+    VIR_AUTOFREE(qemuBlockStatsPtr) bstats = NULL;
     virJSONValuePtr parent;
     virJSONValuePtr parentstats;
     virJSONValuePtr stats;
@@ -2539,11 +2538,11 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("blockstats stats entry was not "
                          "in expected format"));
-        goto cleanup;
+        return NULL;
     }

     if (VIR_ALLOC(bstats) < 0)
-        goto cleanup;
+        return NULL;

 #define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \
     if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \
@@ -2551,7 +2550,7 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev,
         if (virJSONValueObjectGetNumberLong(stats, NAME, &VAR) < 0) { \
             virReportError(VIR_ERR_INTERNAL_ERROR, \
                            _("cannot read %s statistic"), NAME); \
-            goto cleanup; \
+            return NULL; \
         } \
     }
     QEMU_MONITOR_BLOCK_STAT_GET("rd_bytes", bstats->rd_bytes, true);
@@ -2571,11 +2570,7 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev,
             bstats->wr_highest_offset_valid = true;
     }

-    VIR_STEAL_PTR(ret, bstats);
-
- cleanup:
-    VIR_FREE(bstats);
-    return ret;
+    VIR_RETURN_PTR(bstats);
 }


-- 
2.21.0




More information about the libvir-list mailing list