]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
capabilities: reduce scope in virCapabilitiesInitCaches()
authorShaleen Bathla <shaleen.bathla@oracle.com>
Mon, 20 Mar 2023 10:39:56 +0000 (16:09 +0530)
committerJán Tomko <jtomko@redhat.com>
Mon, 20 Mar 2023 13:29:38 +0000 (14:29 +0100)
over-writing a variable in inner while-loop without freeing previous memory
leaks it over time.
To fix this, we can just change scope of bank variable to the inner loop.

Signed-off-by: Shaleen Bathla <shaleen.bathla@oracle.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Fixes: 5c84485439ee63f40002c04914e111395c598db0
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/conf/capabilities.c

index 34770fc4165f30007206c06ec675f73690f59a93..9144ced4984f886c6af7cb6c48a5d4ab969b172b 100644 (file)
@@ -2178,7 +2178,6 @@ virCapabilitiesInitCaches(virCaps *caps)
         int rv = -1;
         g_autoptr(DIR) dirp = NULL;
         g_autofree char *path = g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos);
-        g_autoptr(virCapsHostCacheBank) bank = NULL;
 
         rv = virDirOpenIfExists(&dirp, path);
         if (rv < 0)
@@ -2189,6 +2188,7 @@ virCapabilitiesInitCaches(virCaps *caps)
 
         while ((rv = virDirRead(dirp, &ent, path)) > 0) {
             g_autofree char *type = NULL;
+            g_autoptr(virCapsHostCacheBank) bank = NULL;
             int kernel_type;
             unsigned int level;
             int ret;