]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: manually set dirp to NULL after closing in virCapabilitiesInitCache()
authorLaine Stump <laine@redhat.com>
Mon, 26 Oct 2020 01:10:08 +0000 (21:10 -0400)
committerLaine Stump <laine@redhat.com>
Tue, 3 Nov 2020 03:01:36 +0000 (22:01 -0500)
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 <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/conf/capabilities.c

index 90ad4e0c13e2218a7ee5b7400b77a9470130fe05..18b2612d2e4393fa2e6e4da920a3a11e523e45b1 100644 (file)
@@ -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)