]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu_conf.c: modernize virCPUDefCopyWithoutModel and virCPUDefCopy
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 22 May 2020 19:56:16 +0000 (16:56 -0300)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 25 May 2020 10:31:14 +0000 (12:31 +0200)
Use automatic cleanup of variables.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20200522195620.3843442-2-danielhb413@gmail.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/conf/cpu_conf.c

index 07404c6fb0f2f6a20cde497e6ab560ed2d78ef2e..c6d36e0cb53873226398a23d7a6455a3ed5b98b4 100644 (file)
@@ -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(&copy);
 }
 
 
 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(&copy);
 }