From: Alan T. DeKok Date: Fri, 16 Apr 2021 15:22:06 +0000 (-0400) Subject: rb_remove should return the thing it removed X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8fbb1464387bff280edd33105c4ee50896bbd7bc;p=thirdparty%2Ffreeradius-server.git rb_remove should return the thing it removed --- diff --git a/src/lib/util/rb.c b/src/lib/util/rb.c index 9f1ac5bba2f..9b6ca78ebd8 100644 --- a/src/lib/util/rb.c +++ b/src/lib/util/rb.c @@ -671,26 +671,29 @@ int fr_rb_replace(fr_rb_tree_t *tree, void const *data) * - The user data we removed. * - NULL if we couldn't find any matching data. */ -bool fr_rb_remove(fr_rb_tree_t *tree, void const *data) +void *fr_rb_remove(fr_rb_tree_t *tree, void const *data) { fr_rb_node_t *node; + void *found = NULL; LOCK(tree); - if (unlikely(tree->being_freed)) return false; + if (unlikely(tree->being_freed)) return NULL; node = find_node(tree, data); if (!node) { UNLOCK(tree); - return false; + return NULL; } + found = node->data; + if (unlikely(node->being_freed)) { UNLOCK(tree); - return true; + return found; } delete_internal(tree, node, false); UNLOCK(tree); - return true; + return found; } /** Remove node and free data (if a free function was specified) diff --git a/src/lib/util/rb.h b/src/lib/util/rb.h index dbb53a04b1f..12d9a02ad2d 100644 --- a/src/lib/util/rb.h +++ b/src/lib/util/rb.h @@ -139,7 +139,7 @@ bool fr_rb_insert(fr_rb_tree_t *tree, void const *data) CC_HINT(nonnull); int fr_rb_replace(fr_rb_tree_t *tree, void const *data) CC_HINT(nonnull); -bool fr_rb_remove(fr_rb_tree_t *tree, void const *data) CC_HINT(nonnull); +void *fr_rb_remove(fr_rb_tree_t *tree, void const *data) CC_HINT(nonnull); bool fr_rb_delete(fr_rb_tree_t *tree, void const *data) CC_HINT(nonnull);