virCPUDefPtr
virCPUDefCopyWithoutModel(const virCPUDef *cpu)
{
- virCPUDefPtr copy;
+ g_autoptr(virCPUDef) copy = NULL;
if (!cpu)
return NULL;
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(©);
}
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 copy;
+ return NULL;
- error:
- virCPUDefFree(copy);
- return NULL;
+ return g_steal_pointer(©);
}