]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONGetStatus: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 17 Mar 2021 17:05:52 +0000 (18:05 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 21 Sep 2021 10:25:42 +0000 (12:25 +0200)
Use g_autofree for the JSON values to remove cleanup label and ret
variable.

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

index 8d3c4031a6717df7288bb591f22a7f9dfa330af4..37e9c05d276c5adbf06e36a4a129b6620b05b683 100644 (file)
@@ -1710,10 +1710,9 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon,
                          bool *running,
                          virDomainPausedReason *reason)
 {
-    int ret = -1;
     const char *status;
-    virJSONValue *cmd;
-    virJSONValue *reply = NULL;
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
     virJSONValue *data;
 
     if (reason)
@@ -1723,17 +1722,17 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon,
         return -1;
 
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
-        goto cleanup;
+        return -1;
 
     if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
-        goto cleanup;
+        return -1;
 
     data = virJSONValueObjectGetObject(reply, "return");
 
     if (virJSONValueObjectGetBoolean(data, "running", running) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("query-status reply was missing running state"));
-        goto cleanup;
+        return -1;
     }
 
     if ((status = virJSONValueObjectGetString(data, "status"))) {
@@ -1743,12 +1742,7 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon,
         VIR_DEBUG("query-status reply was missing status details");
     }
 
-    ret = 0;
-
- cleanup:
-    virJSONValueFree(cmd);
-    virJSONValueFree(reply);
-    return ret;
+    return 0;
 }