a41c76
From fc8f77c828ada1bfd3ac4957410f9b4efc659ce1 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <fc8f77c828ada1bfd3ac4957410f9b4efc659ce1@dist-git>
a41c76
From: Jiri Denemark <jdenemar@redhat.com>
a41c76
Date: Tue, 26 May 2020 10:59:17 +0200
a41c76
Subject: [PATCH] cpu_x86: Use g_auto* in x86Encode
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit e6e54fcebe99f1c07fe905c419cbe5d12f6844b1)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Message-Id: <4729842dcc538cca58a2ccd18fe2bcf9be410bbb.1590483392.git.jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/cpu/cpu_x86.c | 51 +++++++++++++++++++----------------------------
a41c76
 1 file changed, 21 insertions(+), 30 deletions(-)
a41c76
a41c76
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
a41c76
index fd410aeafb..56081145c0 100644
a41c76
--- a/src/cpu/cpu_x86.c
a41c76
+++ b/src/cpu/cpu_x86.c
a41c76
@@ -2188,12 +2188,12 @@ x86Encode(virArch arch,
a41c76
           virCPUDataPtr *vendor)
a41c76
 {
a41c76
     virCPUx86MapPtr map = NULL;
a41c76
-    virCPUDataPtr data_forced = NULL;
a41c76
-    virCPUDataPtr data_required = NULL;
a41c76
-    virCPUDataPtr data_optional = NULL;
a41c76
-    virCPUDataPtr data_disabled = NULL;
a41c76
-    virCPUDataPtr data_forbidden = NULL;
a41c76
-    virCPUDataPtr data_vendor = NULL;
a41c76
+    g_autoptr(virCPUData) data_forced = NULL;
a41c76
+    g_autoptr(virCPUData) data_required = NULL;
a41c76
+    g_autoptr(virCPUData) data_optional = NULL;
a41c76
+    g_autoptr(virCPUData) data_disabled = NULL;
a41c76
+    g_autoptr(virCPUData) data_forbidden = NULL;
a41c76
+    g_autoptr(virCPUData) data_vendor = NULL;
a41c76
 
a41c76
     if (forced)
a41c76
         *forced = NULL;
a41c76
@@ -2209,37 +2209,37 @@ x86Encode(virArch arch,
a41c76
         *vendor = NULL;
a41c76
 
a41c76
     if (!(map = virCPUx86GetMap()))
a41c76
-        goto error;
a41c76
+        return -1;
a41c76
 
a41c76
     if (forced &&
a41c76
         (!(data_forced = virCPUDataNew(arch)) ||
a41c76
          x86EncodePolicy(&data_forced->data.x86, cpu, map,
a41c76
                          VIR_CPU_FEATURE_FORCE) < 0))
a41c76
-        goto error;
a41c76
+        return -1;
a41c76
 
a41c76
     if (required &&
a41c76
         (!(data_required = virCPUDataNew(arch)) ||
a41c76
          x86EncodePolicy(&data_required->data.x86, cpu, map,
a41c76
                          VIR_CPU_FEATURE_REQUIRE) < 0))
a41c76
-        goto error;
a41c76
+        return -1;
a41c76
 
a41c76
     if (optional &&
a41c76
         (!(data_optional = virCPUDataNew(arch)) ||
a41c76
          x86EncodePolicy(&data_optional->data.x86, cpu, map,
a41c76
                          VIR_CPU_FEATURE_OPTIONAL) < 0))
a41c76
-        goto error;
a41c76
+        return -1;
a41c76
 
a41c76
     if (disabled &&
a41c76
         (!(data_disabled = virCPUDataNew(arch)) ||
a41c76
          x86EncodePolicy(&data_disabled->data.x86, cpu, map,
a41c76
                          VIR_CPU_FEATURE_DISABLE) < 0))
a41c76
-        goto error;
a41c76
+        return -1;
a41c76
 
a41c76
     if (forbidden &&
a41c76
         (!(data_forbidden = virCPUDataNew(arch)) ||
a41c76
          x86EncodePolicy(&data_forbidden->data.x86, cpu, map,
a41c76
                          VIR_CPU_FEATURE_FORBID) < 0))
a41c76
-        goto error;
a41c76
+        return -1;
a41c76
 
a41c76
     if (vendor) {
a41c76
         virCPUx86VendorPtr v = NULL;
a41c76
@@ -2247,39 +2247,30 @@ x86Encode(virArch arch,
a41c76
         if (cpu->vendor && !(v = x86VendorFind(map, cpu->vendor))) {
a41c76
             virReportError(VIR_ERR_OPERATION_FAILED,
a41c76
                            _("CPU vendor %s not found"), cpu->vendor);
a41c76
-            goto error;
a41c76
+            return -1;
a41c76
         }
a41c76
 
a41c76
         if (!(data_vendor = virCPUDataNew(arch)))
a41c76
-            goto error;
a41c76
+            return -1;
a41c76
 
a41c76
         if (v && virCPUx86DataAdd(data_vendor, &v->data) < 0)
a41c76
-            goto error;
a41c76
+            return -1;
a41c76
     }
a41c76
 
a41c76
     if (forced)
a41c76
-        *forced = data_forced;
a41c76
+        *forced = g_steal_pointer(&data_forced);
a41c76
     if (required)
a41c76
-        *required = data_required;
a41c76
+        *required = g_steal_pointer(&data_required);
a41c76
     if (optional)
a41c76
-        *optional = data_optional;
a41c76
+        *optional = g_steal_pointer(&data_optional);
a41c76
     if (disabled)
a41c76
-        *disabled = data_disabled;
a41c76
+        *disabled = g_steal_pointer(&data_disabled);
a41c76
     if (forbidden)
a41c76
-        *forbidden = data_forbidden;
a41c76
+        *forbidden = g_steal_pointer(&data_forbidden);
a41c76
     if (vendor)
a41c76
-        *vendor = data_vendor;
a41c76
+        *vendor = g_steal_pointer(&data_vendor);
a41c76
 
a41c76
     return 0;
a41c76
-
a41c76
- error:
a41c76
-    virCPUx86DataFree(data_forced);
a41c76
-    virCPUx86DataFree(data_required);
a41c76
-    virCPUx86DataFree(data_optional);
a41c76
-    virCPUx86DataFree(data_disabled);
a41c76
-    virCPUx86DataFree(data_forbidden);
a41c76
-    virCPUx86DataFree(data_vendor);
a41c76
-    return -1;
a41c76
 }
a41c76
 
a41c76
 
a41c76
-- 
a41c76
2.26.2
a41c76