[libvirt] [PATCH 4/5] virsh: Use VIR_AUTO machinery in cmdQemuMonitorCommand

Peter Krempa posted 5 patches 6 years, 4 months ago
[libvirt] [PATCH 4/5] virsh: Use VIR_AUTO machinery in cmdQemuMonitorCommand
Posted by Peter Krempa 6 years, 4 months ago
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tools/virsh-domain.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 9913d703ec..8c24935938 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9506,14 +9506,13 @@ static const vshCmdOptDef opts_qemu_monitor_command[] = {
 static bool
 cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
 {
-    virDomainPtr dom = NULL;
-    bool ret = false;
-    char *monitor_cmd = NULL;
-    char *result = NULL;
+    VIR_AUTOPTR(virshDomain) dom = NULL;
+    VIR_AUTOFREE(char *) monitor_cmd = NULL;
+    VIR_AUTOFREE(char *) result = NULL;
     unsigned int flags = 0;
     const vshCmdOpt *opt = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    virJSONValuePtr pretty = NULL;
+    VIR_AUTOPTR(virJSONValue) pretty = NULL;

     VSH_EXCLUSIVE_OPTIONS("hmp", "pretty");

@@ -9527,7 +9526,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)

     if (virBufferError(&buf)) {
         vshError(ctl, "%s", _("Failed to collect command"));
-        goto cleanup;
+        return false;
     }
     monitor_cmd = virBufferContentAndReset(&buf);

@@ -9535,7 +9534,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;

     if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0)
-        goto cleanup;
+        return false;

     if (vshCommandOptBool(cmd, "pretty")) {
         char *tmp;
@@ -9549,16 +9548,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
         }
     }
     vshPrint(ctl, "%s\n", result);
-
-    ret = true;
-
- cleanup:
-    VIR_FREE(result);
-    VIR_FREE(monitor_cmd);
-    virJSONValueFree(pretty);
-    virshDomainFree(dom);
-
-    return ret;
+    return true;
 }

 /*
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/5] virsh: Use VIR_AUTO machinery in cmdQemuMonitorCommand
Posted by Daniel Henrique Barboza 6 years, 4 months ago

On 9/16/19 9:45 AM, Peter Krempa wrote:
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---

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

>   tools/virsh-domain.c | 24 +++++++-----------------
>   1 file changed, 7 insertions(+), 17 deletions(-)
>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 9913d703ec..8c24935938 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -9506,14 +9506,13 @@ static const vshCmdOptDef opts_qemu_monitor_command[] = {
>   static bool
>   cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
>   {
> -    virDomainPtr dom = NULL;
> -    bool ret = false;
> -    char *monitor_cmd = NULL;
> -    char *result = NULL;
> +    VIR_AUTOPTR(virshDomain) dom = NULL;
> +    VIR_AUTOFREE(char *) monitor_cmd = NULL;
> +    VIR_AUTOFREE(char *) result = NULL;
>       unsigned int flags = 0;
>       const vshCmdOpt *opt = NULL;
>       virBuffer buf = VIR_BUFFER_INITIALIZER;
> -    virJSONValuePtr pretty = NULL;
> +    VIR_AUTOPTR(virJSONValue) pretty = NULL;
>
>       VSH_EXCLUSIVE_OPTIONS("hmp", "pretty");
>
> @@ -9527,7 +9526,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
>
>       if (virBufferError(&buf)) {
>           vshError(ctl, "%s", _("Failed to collect command"));
> -        goto cleanup;
> +        return false;
>       }
>       monitor_cmd = virBufferContentAndReset(&buf);
>
> @@ -9535,7 +9534,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
>           flags |= VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP;
>
>       if (virDomainQemuMonitorCommand(dom, monitor_cmd, &result, flags) < 0)
> -        goto cleanup;
> +        return false;
>
>       if (vshCommandOptBool(cmd, "pretty")) {
>           char *tmp;
> @@ -9549,16 +9548,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
>           }
>       }
>       vshPrint(ctl, "%s\n", result);
> -
> -    ret = true;
> -
> - cleanup:
> -    VIR_FREE(result);
> -    VIR_FREE(monitor_cmd);
> -    virJSONValueFree(pretty);
> -    virshDomainFree(dom);
> -
> -    return ret;
> +    return true;
>   }
>
>   /*

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list