]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONCheckError: Use g_autofree
authorPeter Krempa <pkrempa@redhat.com>
Wed, 18 Mar 2020 09:34:32 +0000 (10:34 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 19 Mar 2020 08:57:45 +0000 (09:57 +0100)
Eliminate cleanup code by using g_autofree.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_monitor_json.c

index 00d7760a05df3ad9f02cbe45f29b98d418b30dbc..31eb01006c0339e0b14fbd8b223beb087507f425 100644 (file)
@@ -393,8 +393,8 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
 {
     if (virJSONValueObjectHasKey(reply, "error")) {
         virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
-        char *cmdstr = virJSONValueToString(cmd, false);
-        char *replystr = virJSONValueToString(reply, false);
+        g_autofree char *cmdstr = virJSONValueToString(cmd, false);
+        g_autofree char *replystr = virJSONValueToString(reply, false);
 
         /* Log the full JSON formatted command & error */
         VIR_DEBUG("unable to execute QEMU command %s: %s",
@@ -411,20 +411,16 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
                            qemuMonitorJSONCommandName(cmd),
                            qemuMonitorJSONStringifyError(error));
 
-        VIR_FREE(cmdstr);
-        VIR_FREE(replystr);
         return -1;
     } else if (!virJSONValueObjectHasKey(reply, "return")) {
-        char *cmdstr = virJSONValueToString(cmd, false);
-        char *replystr = virJSONValueToString(reply, false);
+        g_autofree char *cmdstr = virJSONValueToString(cmd, false);
+        g_autofree char *replystr = virJSONValueToString(reply, false);
 
         VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
                   NULLSTR(cmdstr), NULLSTR(replystr));
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to execute QEMU command '%s'"),
                        qemuMonitorJSONCommandName(cmd));
-        VIR_FREE(cmdstr);
-        VIR_FREE(replystr);
         return -1;
     }
     return 0;