Skip to contentSkip to conversation

libmultipath: add pthread_cleanup hook for udev monitor

PATCH Hannes Reinecke 2 participants 2 messages Sep 15, 2017 – Sep 20, 2017 Device mapper

lore
Share & tools
lore
#0 lore raw

The udev monitor from uevent_listen() needs to be cleaned up from a pthread cleanup hook.
Valgrind complained here.

---
 libmultipath/uevent.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
libmultipath/uevent.c +10 -1
index eb44da56..8b511eb2 100644
@@ -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);
Signature · 1 line
2.12.0
Reviewed-by
#1 lore raw
Quoted 5 lines · Hannes Reinecke

The udev monitor from uevent_listen() needs to be cleaned up from a pthread cleanup hook.
Valgrind complained here.

Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel