[PATCH 17/36] virshParseCPUList: Refactor cleanup

Peter Krempa pkrempa at redhat.com
Thu Dec 9 12:18:22 UTC 2021


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

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tools/virsh-domain.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 8379f9f135..2338d6522a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -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;
 }

-- 
2.31.1




More information about the libvir-list mailing list