From: Arran Cudbard-Bell Date: Fri, 16 Apr 2021 00:30:26 +0000 (-0500) Subject: Hack to alter the behaviour of fr_rb_replace depending on whether in the fr_node_t... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=837add627cd2f1d52eb8daf91551eb5bc2a6733f;p=thirdparty%2Ffreeradius-server.git Hack to alter the behaviour of fr_rb_replace depending on whether in the fr_node_t is inline with the data structure --- diff --git a/src/lib/util/rb.c b/src/lib/util/rb.c index 6be2fd4caae..9d3b3f176bc 100644 --- a/src/lib/util/rb.c +++ b/src/lib/util/rb.c @@ -643,7 +643,19 @@ int fr_rb_replace(fr_rb_tree_t *tree, void const *data) return ret; } old_data = node->data; - node->data = UNCONST(void *, data); + + /* + * If the fr_node_t is inline with the + * data structure, we need to delete + * the old node out of the tree, and + * perform a normal insert operation. + */ + if (tree->node_alloc == _node_inline_alloc) { + delete_internal(tree, node, false); + insert_node(tree, UNCONST(void *, data)); + } else { + node->data = UNCONST(void *, data); + } UNLOCK(tree); if (tree->data_free) tree->data_free(old_data);