1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-06 17:17:56 +03:00

node_device_udev: Fix leak of mdevctlLock, udevThreadCond, and mdevCtlMonitors

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@redhat.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
This commit is contained in:
Marc Hartmayer 2024-04-23 20:08:58 +02:00 committed by Jonathon Jongsma
parent 4daa362706
commit 6e727d8bdc

View File

@ -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);