From 7f42bdf5c021dc79b1062fca13d2d5ac4b735259 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Sun, 25 Oct 2020 21:10:08 -0400 Subject: [PATCH] util: manually set dirp to NULL after closing in virCapabilitiesInitCache() In all uses of VIR_DIR_CLOSE() except one, the DIR* is never referenced after closing all the way until it goes out of scope. virCapabilitiesInitCaches(), however, reuses the same DIR* over and over in a loop, but due to having many error conditions that result in a goto out of the loop, it's not well suited to reducing the scope of the variable until we introduce a g_autoptr cleanup function for DIR*. In preparation for doing just that, we need to get rid of the side effect of VIR_DIR_CLOSE() setting the DIR* to NULL, so in this one case, let's manually set the DIR* to NULL. Then in an upcoming patch we can safely remove the side effect from VIR_DIR_CLOSE(). This extra/ugly bit of code is only temporary: once we introduce the g_autoptr cleanup function for DIR*, we will remove this manual close/clear completely anyway. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/conf/capabilities.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 90ad4e0c13..18b2612d2e 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1865,6 +1865,7 @@ virCapabilitiesInitCaches(virCapsPtr caps) path = g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH, pos); VIR_DIR_CLOSE(dirp); + dirp = NULL; rv = virDirOpenIfExists(&dirp, path); if (rv < 0)