libmultipath: add pthread_cleanup hook for udev monitor
authorHannes Reinecke <hare@suse.de>
Fri, 15 Sep 2017 06:14:30 +0000 (08:14 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 20 Sep 2017 12:02:50 +0000 (14:02 +0200)
The udev monitor from uevent_listen() needs to be cleaned up from
a pthread cleanup hook.
Valgrind complained here.

Signed-off-by: Hannes Reinecke <hare@suse.com>
libmultipath/uevent.c

index eb44da5..8b511eb 100644 (file)
@@ -361,6 +361,14 @@ static void uevent_cleanup(void *arg)
        udev_unref(udev);
 }
 
+static void monitor_cleanup(void *arg)
+{
+       struct udev_monitor *monitor = arg;
+
+       condlog(3, "Releasing uevent_monitor() resources");
+       udev_monitor_unref(monitor);
+}
+
 /*
  * Service the uevent queue.
  */
@@ -749,6 +757,7 @@ int uevent_listen(struct udev *udev)
                condlog(2, "failed to create udev monitor");
                goto out;
        }
+       pthread_cleanup_push(monitor_cleanup, monitor);
 #ifdef LIBUDEV_API_RECVBUF
        if (udev_monitor_set_receive_buffer_size(monitor, 128 * 1024 * 1024))
                condlog(2, "failed to increase buffer size");
@@ -834,7 +843,7 @@ int uevent_listen(struct udev *udev)
        need_failback = 0;
 out:
        if (monitor)
-               udev_monitor_unref(monitor);
+               pthread_cleanup_pop(1);
        if (need_failback)
                err = failback_listen();
        pthread_cleanup_pop(1);