[PATCH v2 12/20] node_device_udev: Fix leak of mdevctlLock, udevThreadCond, and mdevCtlMonitors

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

 



Even if `priv->udev_monitor` was never initialized, the mdevctlLock, udevThread
were. Therefore let's match the order of releasing the resources the order of
allocating the resources in `nodeStateInitialize`.

In addition, use `g_steal_pointer` in `g_list_free_full`.

Reviewed-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx>
---
 src/node_device/node_device_udev.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 9aab4340fa2d..906b16778eef 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -88,6 +88,10 @@ udevEventDataDispose(void *obj)
 
     g_clear_pointer(&priv->initThread, g_free);
 
+    VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) {
+        g_list_free_full(g_steal_pointer(&priv->mdevctlMonitors), g_object_unref);
+    }
+
     if (priv->watch != -1)
         virEventRemoveHandle(priv->watch);
 
@@ -96,16 +100,12 @@ udevEventDataDispose(void *obj)
 
     g_clear_pointer(&priv->udevThread, g_free);
 
-    if (!priv->udev_monitor)
-        return;
-
-    udev = udev_monitor_get_udev(priv->udev_monitor);
-    udev_monitor_unref(priv->udev_monitor);
-    udev_unref(udev);
-
-    VIR_WITH_MUTEX_LOCK_GUARD(&priv->mdevctlLock) {
-        g_list_free_full(priv->mdevctlMonitors, g_object_unref);
+    if (priv->udev_monitor) {
+        udev = udev_monitor_get_udev(priv->udev_monitor);
+        udev_monitor_unref(priv->udev_monitor);
+        udev_unref(udev);
     }
+
     virMutexDestroy(&priv->mdevctlLock);
 
     virCondDestroy(&priv->udevThreadCond);
-- 
2.34.1
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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