]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Use g_auto* in virCPUGetHost
authorTim Wiederhake <twiederh@redhat.com>
Mon, 7 Sep 2020 14:58:56 +0000 (16:58 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 8 Sep 2020 15:41:22 +0000 (17:41 +0200)
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/cpu/cpu.c

index a84eb10cc40c08d3c42f641ed86ea363a4bc8137..69e4205e4b7d76cf1b1b668194c7556a9c9fa29f 100644 (file)
@@ -378,7 +378,7 @@ virCPUGetHost(virArch arch,
               virDomainCapsCPUModelsPtr models)
 {
     struct cpuArchDriver *driver;
-    virCPUDefPtr cpu = NULL;
+    g_autoptr(virCPUDef) cpu = NULL;
 
     VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p, models=%p",
               virArchToString(arch), virCPUTypeToString(type), nodeInfo,
@@ -400,7 +400,7 @@ virCPUGetHost(virArch arch,
             virReportError(VIR_ERR_INVALID_ARG,
                            _("cannot set topology for CPU type '%s'"),
                            virCPUTypeToString(type));
-            goto error;
+            return NULL;
         }
         cpu->type = type;
         break;
@@ -410,7 +410,7 @@ virCPUGetHost(virArch arch,
         virReportError(VIR_ERR_INVALID_ARG,
                        _("unsupported CPU type: %s"),
                        virCPUTypeToString(type));
-        goto error;
+        return NULL;
     }
 
     if (nodeInfo) {
@@ -424,9 +424,8 @@ virCPUGetHost(virArch arch,
      * filled in.
      */
     if (driver->getHost) {
-        if (driver->getHost(cpu, models) < 0 &&
-            !nodeInfo)
-            goto error;
+        if (driver->getHost(cpu, models) < 0 && !nodeInfo)
+            return NULL;
     } else if (nodeInfo) {
         VIR_DEBUG("cannot detect host CPU model for %s architecture",
                   virArchToString(arch));
@@ -434,14 +433,10 @@ virCPUGetHost(virArch arch,
         virReportError(VIR_ERR_NO_SUPPORT,
                        _("cannot detect host CPU model for %s architecture"),
                        virArchToString(arch));
-        goto error;
+        return NULL;
     }
 
-    return cpu;
-
- error:
-    virCPUDefFree(cpu);
-    return NULL;
+    return g_steal_pointer(&cpu);
 }