]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONGetStringArray: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Mon, 14 Jun 2021 14:20:50 +0000 (16:20 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 15 Jun 2021 14:58:23 +0000 (16:58 +0200)
Use automatic memory clearing to simplify the control flow.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_monitor_json.c

index 683b3896707f108aa19d79bdb31ba85614c19c1d..c25e282d514d569a5f22ea91349e82f7b8031eca 100644 (file)
@@ -7201,12 +7201,12 @@ qemuMonitorJSONBlockExportAdd(qemuMonitor *mon,
 
 
 static int
-qemuMonitorJSONGetStringArray(qemuMonitor *mon, const char *qmpCmd,
+qemuMonitorJSONGetStringArray(qemuMonitor *mon,
+                              const char *qmpCmd,
                               char ***array)
 {
-    int ret = -1;
-    virJSONValue *cmd;
-    virJSONValue *reply = NULL;
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
 
     *array = NULL;
 
@@ -7214,25 +7214,18 @@ qemuMonitorJSONGetStringArray(qemuMonitor *mon, const char *qmpCmd,
         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;
 
     if (!(*array = virJSONValueObjectGetStringArray(reply, "return")))
-        goto cleanup;
-
-    ret = g_strv_length(*array);
+        return -1;
 
- cleanup:
-    virJSONValueFree(cmd);
-    virJSONValueFree(reply);
-    return ret;
+    return g_strv_length(*array);
 }
 
 int qemuMonitorJSONGetTPMModels(qemuMonitor *mon,