]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Handle node deletions when walking over the tree.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 11 May 2011 08:55:56 +0000 (10:55 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 11 May 2011 08:57:44 +0000 (10:57 +0200)
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.

src/lib/rbtree.c

index 3a5a7ca2210742237cf489ce1f395aa664fcd895..e5234420728fa3b480d90a5eaa66cc683b05f44a 100644 (file)
@@ -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;
        }