]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
rb_remove should return the thing it removed
authorAlan T. DeKok <aland@freeradius.org>
Fri, 16 Apr 2021 15:22:06 +0000 (11:22 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 16 Apr 2021 15:22:27 +0000 (11:22 -0400)
src/lib/util/rb.c
src/lib/util/rb.h

index 9f1ac5bba2f7f2c63e78c4b37a9d4fcb0e147d92..9b6ca78ebd89ab41c06b8dc79a84772e1b6ef1c3 100644 (file)
@@ -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)
index dbb53a04b1ff1e15b5a7b7e9964f86239dd3e297..12d9a02ad2df49b1fb449da35bced0585382d994 100644 (file)
@@ -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);