Re: [PATCH 4/5] qemu_driver.c: modernize qemuConnectCPUModelComparison()

2020-07-21 Thread Jiri Denemark
On Fri, Jul 17, 2020 at 18:15:55 -0300, Daniel Henrique Barboza wrote:
> Use g_auto* on pointers to avoid using the 'cleanup' label.
> 
> In theory the 'ret' variable can also be discarded if the flow
> of the logic is reworked. Perhaps another time.

Doing so would actually be pretty easy, mostly ret = ...; would need to
be replaced with direct return. I'll send a trivial patch doing this.

Jirka



[PATCH 4/5] qemu_driver.c: modernize qemuConnectCPUModelComparison()

2020-07-17 Thread Daniel Henrique Barboza
Use g_auto* on pointers to avoid using the 'cleanup' label.

In theory the 'ret' variable can also be discarded if the flow
of the logic is reworked. Perhaps another time.

Signed-off-by: Daniel Henrique Barboza 
---
 src/qemu/qemu_driver.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d73d093465..393a7e27cb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13147,19 +13147,19 @@ qemuConnectCPUModelComparison(virQEMUCapsPtr qemuCaps,
   virCPUDefPtr cpu_b,
   bool failIncompatible)
 {
-qemuProcessQMPPtr proc = NULL;
-char *result = NULL;
+g_autoptr(qemuProcessQMP) proc = NULL;
+g_autofree char *result = NULL;
 int ret = VIR_CPU_COMPARE_ERROR;
 
 if (!(proc = qemuProcessQMPNew(virQEMUCapsGetBinary(qemuCaps),
libDir, runUid, runGid, false)))
-goto cleanup;
+return VIR_CPU_COMPARE_ERROR;
 
 if (qemuProcessQMPStart(proc) < 0)
-goto cleanup;
+return VIR_CPU_COMPARE_ERROR;
 
 if (qemuMonitorGetCPUModelComparison(proc->mon, cpu_a, cpu_b, ) < 0)
-goto cleanup;
+return VIR_CPU_COMPARE_ERROR;
 
 if (STREQ(result, "identical"))
 ret = VIR_CPU_COMPARE_IDENTICAL;
@@ -13170,9 +13170,6 @@ qemuConnectCPUModelComparison(virQEMUCapsPtr qemuCaps,
 else
 ret = VIR_CPU_COMPARE_INCOMPATIBLE;
 
- cleanup:
-VIR_FREE(result);
-qemuProcessQMPFree(proc);
 return ret;
 }
 
-- 
2.26.2