[PATCH 01/36] virCapabilitiesInitCaches: Refactor freeing of temporary variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move the 'path' and 'type' variables down to the appropriate block and
use automatic freeing for them as well as the temporary virBitmap.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/capabilities.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index cea4803fc8..34295ec4d7 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -2155,11 +2155,9 @@ int
 virCapabilitiesInitCaches(virCaps *caps)
 {
     size_t i = 0;
-    virBitmap *cpus = NULL;
+    g_autoptr(virBitmap) cpus = NULL;
     ssize_t pos = -1;
     int ret = -1;
-    char *path = NULL;
-    char *type = NULL;
     struct dirent *ent = NULL;
     virCapsHostCacheBank *bank = NULL;
     const virResctrlMonitorType montype = VIR_RESCTRL_MONITOR_TYPE_CACHE;
@@ -2180,9 +2178,7 @@ virCapabilitiesInitCaches(virCaps *caps)
     while ((pos = virBitmapNextSetBit(cpus, pos)) >= 0) {
         int rv = -1;
         g_autoptr(DIR) dirp = NULL;
-
-        VIR_FREE(path);
-        path = g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos);
+        g_autofree char *path = g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos);

         rv = virDirOpenIfExists(&dirp, path);
         if (rv < 0)
@@ -2192,6 +2188,7 @@ virCapabilitiesInitCaches(virCaps *caps)
             continue;

         while ((rv = virDirRead(dirp, &ent, path)) > 0) {
+            g_autofree char *type = NULL;
             int kernel_type;
             unsigned int level;

@@ -2242,7 +2239,6 @@ virCapabilitiesInitCaches(virCaps *caps)
             }

             bank->type = kernel_type;
-            VIR_FREE(type);

             for (i = 0; i < caps->host.cache.nbanks; i++) {
                 if (virCapsHostCacheBankEquals(bank, caps->host.cache.banks[i]))
@@ -2284,10 +2280,7 @@ virCapabilitiesInitCaches(virCaps *caps)

     ret = 0;
  cleanup:
-    VIR_FREE(type);
-    VIR_FREE(path);
     virCapsHostCacheBankFree(bank);
-    virBitmapFree(cpus);
     return ret;
 }

-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux