virshParseCPUList: Refactor cleanup

Use automatic memory freeing for the temporary bitmap and remove the
pointless 'cleanup' section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-12-07 17:22:26 +01:00
parent babbfb5be9
commit 33eb88cdc9
1 changed files with 4 additions and 6 deletions

View File

@ -6983,7 +6983,7 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen,
const char *cpulist, int maxcpu)
{
unsigned char *cpumap = NULL;
virBitmap *map = NULL;
g_autoptr(virBitmap) map = NULL;
if (cpulist[0] == 'r') {
map = virBitmapNew(maxcpu);
@ -6994,21 +6994,19 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen,
if (virBitmapParse(cpulist, &map, 1024) < 0 ||
virBitmapIsAllClear(map)) {
vshError(ctl, _("Invalid cpulist '%s'"), cpulist);
goto cleanup;
return NULL;
}
lastcpu = virBitmapLastSetBit(map);
if (lastcpu >= maxcpu) {
vshError(ctl, _("CPU %d in cpulist '%s' exceed the maxcpu %d"),
lastcpu, cpulist, maxcpu);
goto cleanup;
return NULL;
}
}
if (virBitmapToData(map, &cpumap, cpumaplen) < 0)
goto cleanup;
return NULL;
cleanup:
virBitmapFree(map);
return cpumap;
}