]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virResctrlAllocNewFromInfo: Restrict variable scope and use automatic freeing
authorPeter Krempa <pkrempa@redhat.com>
Tue, 23 Mar 2021 16:11:42 +0000 (17:11 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 12 Apr 2021 13:55:10 +0000 (15:55 +0200)
Move variables into the loop which uses them and use automatic freeing
for temporarily allocated variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virresctrl.c

index fbc8e9c7669ba282b9409a052a3c352781e1fdd1..5e7c3915240417464c8891c0473107841ddb3b4b 100644 (file)
@@ -1811,27 +1811,26 @@ static virResctrlAllocPtr
 virResctrlAllocNewFromInfo(virResctrlInfoPtr info)
 {
     size_t i = 0;
-    size_t j = 0;
-    size_t k = 0;
     virResctrlAllocPtr ret = virResctrlAllocNew();
-    virBitmapPtr mask = NULL;
 
     if (!ret)
         return NULL;
 
     for (i = 0; i < info->nlevels; i++) {
         virResctrlInfoPerLevelPtr i_level = info->levels[i];
+        size_t j = 0;
 
         if (!i_level)
             continue;
 
         for (j = 0; j < VIR_CACHE_TYPE_LAST; j++) {
             virResctrlInfoPerTypePtr i_type = i_level->types[j];
+            g_autoptr(virBitmap) mask = NULL;
+            size_t k = 0;
 
             if (!i_type)
                 continue;
 
-            virBitmapFree(mask);
             mask = virBitmapNew(i_type->bits);
             virBitmapSetAll(mask);
 
@@ -1856,7 +1855,6 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info)
     }
 
  cleanup:
-    virBitmapFree(mask);
     return ret;
  error:
     virObjectUnref(ret);