]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu_x86: Use g_auto* in x86Encode
authorJiri Denemark <jdenemar@redhat.com>
Wed, 25 Mar 2020 09:33:27 +0000 (10:33 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 8 Apr 2020 15:41:01 +0000 (17:41 +0200)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/cpu/cpu_x86.c

index 67387df23e2dc7215ff39585a4629c1164016f8d..afdde24754f84c4639b69972e9b7a97a91f6ca3d 100644 (file)
@@ -2188,12 +2188,12 @@ x86Encode(virArch arch,
           virCPUDataPtr *vendor)
 {
     virCPUx86MapPtr map = NULL;
-    virCPUDataPtr data_forced = NULL;
-    virCPUDataPtr data_required = NULL;
-    virCPUDataPtr data_optional = NULL;
-    virCPUDataPtr data_disabled = NULL;
-    virCPUDataPtr data_forbidden = NULL;
-    virCPUDataPtr data_vendor = NULL;
+    g_autoptr(virCPUData) data_forced = NULL;
+    g_autoptr(virCPUData) data_required = NULL;
+    g_autoptr(virCPUData) data_optional = NULL;
+    g_autoptr(virCPUData) data_disabled = NULL;
+    g_autoptr(virCPUData) data_forbidden = NULL;
+    g_autoptr(virCPUData) data_vendor = NULL;
 
     if (forced)
         *forced = NULL;
@@ -2209,37 +2209,37 @@ x86Encode(virArch arch,
         *vendor = NULL;
 
     if (!(map = virCPUx86GetMap()))
-        goto error;
+        return -1;
 
     if (forced &&
         (!(data_forced = virCPUDataNew(arch)) ||
          x86EncodePolicy(&data_forced->data.x86, cpu, map,
                          VIR_CPU_FEATURE_FORCE) < 0))
-        goto error;
+        return -1;
 
     if (required &&
         (!(data_required = virCPUDataNew(arch)) ||
          x86EncodePolicy(&data_required->data.x86, cpu, map,
                          VIR_CPU_FEATURE_REQUIRE) < 0))
-        goto error;
+        return -1;
 
     if (optional &&
         (!(data_optional = virCPUDataNew(arch)) ||
          x86EncodePolicy(&data_optional->data.x86, cpu, map,
                          VIR_CPU_FEATURE_OPTIONAL) < 0))
-        goto error;
+        return -1;
 
     if (disabled &&
         (!(data_disabled = virCPUDataNew(arch)) ||
          x86EncodePolicy(&data_disabled->data.x86, cpu, map,
                          VIR_CPU_FEATURE_DISABLE) < 0))
-        goto error;
+        return -1;
 
     if (forbidden &&
         (!(data_forbidden = virCPUDataNew(arch)) ||
          x86EncodePolicy(&data_forbidden->data.x86, cpu, map,
                          VIR_CPU_FEATURE_FORBID) < 0))
-        goto error;
+        return -1;
 
     if (vendor) {
         virCPUx86VendorPtr v = NULL;
@@ -2247,39 +2247,30 @@ x86Encode(virArch arch,
         if (cpu->vendor && !(v = x86VendorFind(map, cpu->vendor))) {
             virReportError(VIR_ERR_OPERATION_FAILED,
                            _("CPU vendor %s not found"), cpu->vendor);
-            goto error;
+            return -1;
         }
 
         if (!(data_vendor = virCPUDataNew(arch)))
-            goto error;
+            return -1;
 
         if (v && virCPUx86DataAdd(data_vendor, &v->data) < 0)
-            goto error;
+            return -1;
     }
 
     if (forced)
-        *forced = data_forced;
+        *forced = g_steal_pointer(&data_forced);
     if (required)
-        *required = data_required;
+        *required = g_steal_pointer(&data_required);
     if (optional)
-        *optional = data_optional;
+        *optional = g_steal_pointer(&data_optional);
     if (disabled)
-        *disabled = data_disabled;
+        *disabled = g_steal_pointer(&data_disabled);
     if (forbidden)
-        *forbidden = data_forbidden;
+        *forbidden = g_steal_pointer(&data_forbidden);
     if (vendor)
-        *vendor = data_vendor;
+        *vendor = g_steal_pointer(&data_vendor);
 
     return 0;
-
- error:
-    virCPUx86DataFree(data_forced);
-    virCPUx86DataFree(data_required);
-    virCPUx86DataFree(data_optional);
-    virCPUx86DataFree(data_disabled);
-    virCPUx86DataFree(data_forbidden);
-    virCPUx86DataFree(data_vendor);
-    return -1;
 }