]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
re-initialize the iterator for every module we delete
authorAlan T. DeKok <aland@freeradius.org>
Mon, 30 Jan 2023 20:27:34 +0000 (15:27 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 30 Jan 2023 20:27:34 +0000 (15:27 -0500)
because deleting one module may cause it to delete child modules
in the tree, which confuses the iterator and makes it sad.

src/lib/server/module.c

index 85632c45b9d5cc8e778698f9c97b89096355cb29..0c16462bf709a7c209fa29be3b1cad095acd0101 100644 (file)
@@ -1064,12 +1064,12 @@ static int _module_list_free(module_list_t *ml)
        module_instance_t       *mi;
 
        /*
-        *      We explicitly free modules so that
-        *      they're done in a stable order.
+        *      Re-initialize the iterator after freeing each module.
+        *      The module may have children which are also in the
+        *      tree.  It can cause problems when we delete children
+        *      without the iterator knowing about it.
         */
-       for (mi = fr_rb_iter_init_inorder(&iter, ml->name_tree);
-            mi;
-            mi = fr_rb_iter_next_inorder(&iter)) {
+       while ((mi = fr_rb_iter_init_inorder(&iter, ml->name_tree)) != NULL) {
                fr_rb_iter_delete_inorder(&iter);       /* Keeps the iterator sane */
                talloc_free(mi);
        }