Re: [PATCH] qemuMonitorJSONCheckReply: Use g_autofree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The commit title is a bit misleading because you're changing
qemuMonitorJSONCheckErrorFull() as well. I suggest changing it to:


"qemu_monitor_json.c: use g_autofree"

And then you cam mention the functions you're changing in the commit
message:


"Eliminate cleanup code by using g_autofree in qemuMonitorJSONCheckErrorFull()
and qemuMonitorJSONCheckReply()"


On 10/15/20 11:17 PM, Yi Li wrote:
Eliminate cleanup code by using g_autofree.

Signed-off-by: Yi Li <yili@xxxxxxxxxxx>
---

The code LGTM. With the commit title/msg changes:


Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>


  src/qemu/qemu_monitor_json.c | 13 +++++--------
  1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 26ac499fc5..f76b369191 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -392,10 +392,11 @@ qemuMonitorJSONCheckErrorFull(virJSONValuePtr cmd,
                                virJSONValuePtr reply,
                                bool report)
  {
+    g_autofree char *cmdstr = virJSONValueToString(cmd, false);
+    g_autofree char *replystr = virJSONValueToString(reply, false);
+
      if (virJSONValueObjectHasKey(reply, "error")) {
          virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
-        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",
@@ -417,8 +418,6 @@ qemuMonitorJSONCheckErrorFull(virJSONValuePtr cmd,
return -1;
      } else if (!virJSONValueObjectHasKey(reply, "return")) {
-        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));
@@ -455,8 +454,8 @@ qemuMonitorJSONCheckReply(virJSONValuePtr cmd,
data = virJSONValueObjectGet(reply, "return");
      if (virJSONValueGetType(data) != type) {
-        char *cmdstr = virJSONValueToString(cmd, false);
-        char *retstr = virJSONValueToString(data, false);
+        g_autofree char *cmdstr = virJSONValueToString(cmd, false);
+        g_autofree char *retstr = virJSONValueToString(data, false);
VIR_DEBUG("Unexpected return type %d (expecting %d) for command %s: %s",
                    virJSONValueGetType(data), type, cmdstr, retstr);
@@ -464,8 +463,6 @@ qemuMonitorJSONCheckReply(virJSONValuePtr cmd,
                         _("unexpected type returned by QEMU command '%s'"),
                         qemuMonitorJSONCommandName(cmd));
- VIR_FREE(cmdstr);
-        VIR_FREE(retstr);
          return -1;
      }




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux