render / rpms / libvirt

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