From: Laine Stump Date: Mon, 26 Oct 2020 01:10:08 +0000 (-0400) Subject: util: manually set dirp to NULL after closing in virCapabilitiesInitCache() X-Git-Tag: v6.10.0-rc1~394 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f42bdf5c021dc79b1062fca13d2d5ac4b735259;p=thirdparty%2Flibvirt.git 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 --- 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)