]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
udev: Fix memleak
authorMariusz Tkaczyk <mariusz.tkaczyk@dell.com>
Tue, 23 Sep 2025 06:06:12 +0000 (08:06 +0200)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Tue, 14 Oct 2025 05:25:44 +0000 (07:25 +0200)
According to manual:
On success, udev_monitor_receive_device() returns a pointer to a newly
referenced device that was received via the monitor. The caller is
responsible to drop this reference when done.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@dell.com>
udev.c

diff --git a/udev.c b/udev.c
index 961ca970d46009c95a6ce51103135c9fc971dead..f857c723e4a160779ec37a87337be7b2ab3a8252 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -147,9 +147,16 @@ enum udev_status udev_wait_for_events(int seconds)
        tv.tv_sec = seconds;
        tv.tv_usec = 0;
 
-       if (select(fd + 1, &readfds, NULL, NULL, &tv) > 0 && FD_ISSET(fd, &readfds))
-               if (udev_monitor_receive_device(udev_monitor))
+       if (select(fd + 1, &readfds, NULL, NULL, &tv) > 0 && FD_ISSET(fd, &readfds)) {
+               struct udev_device *dev = udev_monitor_receive_device(udev_monitor);
+
+               if (dev) {
+                       udev_device_unref(dev);
                        return UDEV_STATUS_SUCCESS; /* event detected */
+               } else {
+                       return UDEV_STATUS_ERROR;
+               }
+       }
        return UDEV_STATUS_TIMEOUT;
 }
 #endif