]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuAgentCheckError: use g_autofree
authorPeter Krempa <pkrempa@redhat.com>
Fri, 13 Mar 2020 08:43:10 +0000 (09:43 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Mar 2020 11:02:20 +0000 (12:02 +0100)
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_agent.c

index 0300dff3e595f66df4b7b0915e1367ab408f1b34..56181d5404ff2d3d2888a0fbbe99224d93135f74 100644 (file)
@@ -1055,8 +1055,8 @@ qemuAgentCheckError(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 agent command %s: %s",
@@ -1073,20 +1073,16 @@ qemuAgentCheckError(virJSONValuePtr cmd,
                            qemuAgentCommandName(cmd),
                            qemuAgentStringifyError(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 agent command '%s'"),
                        qemuAgentCommandName(cmd));
-        VIR_FREE(cmdstr);
-        VIR_FREE(replystr);
         return -1;
     }
     return 0;