[PATCH] qemuMonitorJSONCheckReply: Use g_autofree

Daniel Henrique Barboza danielhb413 at gmail.com
Fri Oct 16 13:48:29 UTC 2020


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 at winhong.com>
> ---

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


Reviewed-by: Daniel Henrique Barboza <danielhb413 at gmail.com>


>   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;
>       }
>   
> 




More information about the libvir-list mailing list