1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

cpu_conf.c: modernize virCPUDefCopyWithoutModel and virCPUDefCopy

Use automatic cleanup of variables.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Message-Id: <20200522195620.3843442-2-danielhb413@gmail.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2020-05-22 16:56:16 -03:00 committed by Jiri Denemark
parent f718709431
commit 43da417b61

View File

@ -227,7 +227,7 @@ virCPUDefStealModel(virCPUDefPtr dst,
virCPUDefPtr
virCPUDefCopyWithoutModel(const virCPUDef *cpu)
{
virCPUDefPtr copy;
g_autoptr(virCPUDef) copy = NULL;
if (!cpu)
return NULL;
@ -246,42 +246,34 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu)
if (cpu->cache) {
if (VIR_ALLOC(copy->cache) < 0)
goto error;
return NULL;
*copy->cache = *cpu->cache;
}
if (cpu->tsc) {
if (VIR_ALLOC(copy->tsc) < 0)
goto error;
return NULL;
*copy->tsc = *cpu->tsc;
}
return copy;
error:
virCPUDefFree(copy);
return NULL;
return g_steal_pointer(&copy);
}
virCPUDefPtr
virCPUDefCopy(const virCPUDef *cpu)
{
virCPUDefPtr copy;
g_autoptr(virCPUDef) copy = NULL;
if (!(copy = virCPUDefCopyWithoutModel(cpu)))
return NULL;
if (virCPUDefCopyModel(copy, cpu, false) < 0)
goto error;
return NULL;
return copy;
error:
virCPUDefFree(copy);
return NULL;
return g_steal_pointer(&copy);
}