From 7edf99d8905af253236732cf538d2b6d1a0c4243 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 Nov 2013 01:15:31 +0100 Subject: libudev: always return NULL in _unref() APIs Returning anything else but NULL would suggest the caller's reference might still be valid, but it isn't, because the caller just invoked _unref() after all. This turns the return value into a typesafe shortcut that allows unreffing and resetting a reference in one line. In contrast to solutions for this which take a pointer to a pointer to accomplish the same this solution is just syntactic sugar the developer can make use of but doesn't have to, and this is particularly useful when immediately unreffing objects returned by function calls. Signed-off-by: Anthony G. Basile --- src/libudev/libudev-monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libudev/libudev-monitor.c') diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 91f6a0806a..853705e4f8 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -408,7 +408,7 @@ _public_ struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor * the bound socket will be closed, and the resources of the monitor * will be released. * - * Returns: the passed udev monitor if it has still an active reference, or #NULL otherwise. + * Returns: #NULL **/ _public_ struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor) { @@ -416,7 +416,7 @@ _public_ struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monit return NULL; udev_monitor->refcount--; if (udev_monitor->refcount > 0) - return udev_monitor; + return NULL; if (udev_monitor->sock >= 0) close(udev_monitor->sock); udev_list_cleanup(&udev_monitor->filter_subsystem_list); -- cgit v1.2.3-54-g00ecf