diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-19 01:15:31 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-20 19:36:14 +0100 |
commit | 725d7e6cebcafef3bd4adbf76c8fa73a9b18972e (patch) | |
tree | 0f11bd0acef710d24a462b66555a2ccfe0249494 /src/libudev/libudev-enumerate.c | |
parent | 994e023433e020e2b3f683d5d1f2c974db580447 (diff) |
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.
Diffstat (limited to 'src/libudev/libudev-enumerate.c')
-rw-r--r-- | src/libudev/libudev-enumerate.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index e71d766c02..48ffe83d36 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -122,7 +122,7 @@ _public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_e * Drop a reference of an enumeration context. If the refcount reaches zero, * all resources of the enumeration context will be released. * - * Returns: the passed enumeration context if it has still an active reference, or #NULL otherwise. + * Returns: #NULL **/ _public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate) { @@ -132,7 +132,7 @@ _public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev return NULL; udev_enumerate->refcount--; if (udev_enumerate->refcount > 0) - return udev_enumerate; + return NULL; udev_list_cleanup(&udev_enumerate->sysattr_match_list); udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list); udev_list_cleanup(&udev_enumerate->subsystem_match_list); |