Re: [PATCH 1/5] cpu_conf.c: modernize virCPUDefCopyWithoutModel and virCPUDefCopy

2020-05-25 Thread Jiri Denemark
On Fri, May 22, 2020 at 16:56:16 -0300, Daniel Henrique Barboza wrote:
> Use automatic cleanup of variables.
> 
> Signed-off-by: Daniel Henrique Barboza 
> ---
>  src/conf/cpu_conf.c | 22 +++---
>  1 file changed, 7 insertions(+), 15 deletions(-)

Reviewed-by: Jiri Denemark 



[PATCH 1/5] cpu_conf.c: modernize virCPUDefCopyWithoutModel and virCPUDefCopy

2020-05-22 Thread Daniel Henrique Barboza
Use automatic cleanup of variables.

Signed-off-by: Daniel Henrique Barboza 
---
 src/conf/cpu_conf.c | 22 +++---
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 07404c6fb0..c6d36e0cb5 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -227,7 +227,7 @@ virCPUDefStealModel(virCPUDefPtr dst,
 virCPUDefPtr
 virCPUDefCopyWithoutModel(const virCPUDef *cpu)
 {
-virCPUDefPtr copy;
+g_autoptr(virCPUDef) copy = NULL;
 
 if (!cpu)
 return NULL;
@@ -246,42 +246,34 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu)
 
 if (cpu->cache) {
 if (VIR_ALLOC(copy->cache) < 0)
-goto error;
+return NULL;
 
 *copy->cache = *cpu->cache;
 }
 
 if (cpu->tsc) {
 if (VIR_ALLOC(copy->tsc) < 0)
-goto error;
+return NULL;
 
 *copy->tsc = *cpu->tsc;
 }
 
-return copy;
-
- error:
-virCPUDefFree(copy);
-return NULL;
+return g_steal_pointer();
 }
 
 
 virCPUDefPtr
 virCPUDefCopy(const virCPUDef *cpu)
 {
-virCPUDefPtr copy;
+g_autoptr(virCPUDef) copy = NULL;
 
 if (!(copy = virCPUDefCopyWithoutModel(cpu)))
 return NULL;
 
 if (virCPUDefCopyModel(copy, cpu, false) < 0)
-goto error;
-
-return copy;
+return NULL;
 
- error:
-virCPUDefFree(copy);
-return NULL;
+return g_steal_pointer();
 }
 
 
-- 
2.26.2