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.
This commit is contained in:
Lennart Poettering
2013-11-20 19:36:14 +01:00
parent 994e023433
commit 725d7e6ceb
5 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -101,7 +101,7 @@ _public_ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue)
* Drop a reference of a udev queue context. If the refcount reaches zero,
* the resources of the queue context will be released.
*
* Returns: the passed queue context if it has still an active reference, or #NULL otherwise.
* Returns: #NULL
**/
_public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
{
@@ -109,7 +109,7 @@ _public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
return NULL;
udev_queue->refcount--;
if (udev_queue->refcount > 0)
return udev_queue;
return NULL;
udev_list_cleanup(&udev_queue->queue_list);
free(udev_queue);
return NULL;