]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virshDomainGetVcpuBitmap: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 15 Sep 2021 13:13:24 +0000 (15:13 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 15 Sep 2021 13:31:17 +0000 (15:31 +0200)
Rename the temp variable that is being returned and use automatic
pointer clearing for it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tools/virsh-domain.c

index f5a3e1accc834d2bebf8d89a4a92ed36ca8b1b93..4d328d217454fdb0240bd4ede0b50ca6a948ed37 100644 (file)
@@ -6677,7 +6677,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
                          bool inactive)
 {
     unsigned int flags = 0;
-    virBitmap *ret = NULL;
+    g_autoptr(virBitmap) cpumap = NULL;
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
@@ -6703,14 +6703,14 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
     if (curvcpus == 0)
         curvcpus = maxvcpus;
 
-    ret = virBitmapNew(maxvcpus);
+    cpumap = virBitmapNew(maxvcpus);
 
     if ((nnodes = virXPathNodeSet("/domain/vcpus/vcpu", ctxt, &nodes)) <= 0) {
         /* if the specific vcpu state is missing provide a fallback */
         for (i = 0; i < curvcpus; i++)
-            ignore_value(virBitmapSetBit(ret, i));
+            ignore_value(virBitmapSetBit(cpumap, i));
 
-        return ret;
+        return g_steal_pointer(&cpumap);
     }
 
     for (i = 0; i < nnodes; i++) {
@@ -6723,16 +6723,15 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
             continue;
 
         if (STREQ(online, "yes"))
-            ignore_value(virBitmapSetBit(ret, vcpuid));
+            ignore_value(virBitmapSetBit(cpumap, vcpuid));
     }
 
-    if (virBitmapCountBits(ret) != curvcpus) {
+    if (virBitmapCountBits(cpumap) != curvcpus) {
         vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap"));
-        virBitmapFree(ret);
         return NULL;
     }
 
-    return ret;
+    return g_steal_pointer(&cpumap);
 }