From d369264a994f2fd7d97c2494500dc20dfaabb360 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Mon, 7 Sep 2020 16:58:56 +0200 Subject: [PATCH] cpu: Use g_auto* in virCPUGetHost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tim Wiederhake Reviewed-by: Ján Tomko Signed-off-by: Ján Tomko --- src/cpu/cpu.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index a84eb10cc4..69e4205e4b 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -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); }