From: Alan T. DeKok Date: Wed, 11 May 2011 08:55:56 +0000 (+0200) Subject: Handle node deletions when walking over the tree. X-Git-Tag: release_2_1_11~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8d063e89315e13d7fa5d5839d4881c560ee16e1;p=thirdparty%2Ffreeradius-server.git Handle node deletions when walking over the tree. The current node may be deleted, so we cache the left/right pointers where necessary, and use the cached versions instead of de-referencing the current node again. --- diff --git a/src/lib/rbtree.c b/src/lib/rbtree.c index 3a5a7ca2210..e5234420728 100644 --- a/src/lib/rbtree.c +++ b/src/lib/rbtree.c @@ -511,17 +511,21 @@ static int WalkNodePreOrder(rbnode_t *X, int (*callback)(void *, void *), void *context) { int rcode; + rbnode_t *Left, *Right; + + Left = X->Left; + Right = X->Right; rcode = callback(context, X->Data); if (rcode != 0) return rcode; - if (X->Left != NIL) { - rcode = WalkNodePreOrder(X->Left, callback, context); + if (Left != NIL) { + rcode = WalkNodePreOrder(Left, callback, context); if (rcode != 0) return rcode; } - if (X->Right != NIL) { - rcode = WalkNodePreOrder(X->Right, callback, context); + if (Right != NIL) { + rcode = WalkNodePreOrder(Right, callback, context); if (rcode != 0) return rcode; } @@ -535,17 +539,20 @@ static int WalkNodeInOrder(rbnode_t *X, int (*callback)(void *, void *), void *context) { int rcode; + rbnode_t *Right; if (X->Left != NIL) { rcode = WalkNodeInOrder(X->Left, callback, context); if (rcode != 0) return rcode; } + Right = X->Right; + rcode = callback(context, X->Data); if (rcode != 0) return rcode; - if (X->Right != NIL) { - rcode = WalkNodeInOrder(X->Right, callback, context); + if (Right != NIL) { + rcode = WalkNodeInOrder(Right, callback, context); if (rcode != 0) return rcode; }