[PATCH 03/13] qemuMonitorJSONGetMigrationCapabilities: Refactor cleanup

Peter Krempa pkrempa at redhat.com
Tue Jun 15 10:27:16 UTC 2021


Use automatic memory clearing and remove the cleanup section.

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

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 64696da210..f0d67f8f20 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6768,11 +6768,10 @@ int
 qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon,
                                         char ***capabilities)
 {
-    int ret = -1;
-    virJSONValue *cmd;
-    virJSONValue *reply = NULL;
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
     virJSONValue *caps;
-    char **list = NULL;
+    g_auto(GStrv) list = NULL;
     size_t i;
     size_t n;

@@ -6783,15 +6782,13 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon,
         return -1;

     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
-        goto cleanup;
+        return -1;

-    if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
-        ret = 0;
-        goto cleanup;
-    }
+    if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
+        return 0;

     if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0)
-        goto cleanup;
+        return -1;

     caps = virJSONValueObjectGetArray(reply, "return");
     n = virJSONValueArraySize(caps);
@@ -6805,26 +6802,20 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon,
         if (!cap || virJSONValueGetType(cap) != VIR_JSON_TYPE_OBJECT) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("missing entry in migration capabilities list"));
-            goto cleanup;
+            return -1;
         }

         if (!(name = virJSONValueObjectGetString(cap, "capability"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("missing migration capability name"));
-            goto cleanup;
+            return -1;
         }

         list[i] = g_strdup(name);
     }

-    ret = n;
     *capabilities = g_steal_pointer(&list);
-
- cleanup:
-    g_strfreev(list);
-    virJSONValueFree(cmd);
-    virJSONValueFree(reply);
-    return ret;
+    return n;
 }


-- 
2.31.1




More information about the libvir-list mailing list