[PATCH 3/3] libsepol/cil: Simplify cil_tree_children_destroy()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use a simpler recursive solution and set the head and tail pointers
of the starting node to NULL when done.

Remove the now uneeded setting of the head and tail pointers to NULL
in cil_resolve_in().

Signed-off-by: James Carter <jwcart2@xxxxxxxxx>
---
 libsepol/cil/src/cil_resolve_ast.c |  2 --
 libsepol/cil/src/cil_tree.c        | 33 +++++++++---------------------
 2 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/libsepol/cil/src/cil_resolve_ast.c b/libsepol/cil/src/cil_resolve_ast.c
index aeedc7dd..60dbd163 100644
--- a/libsepol/cil/src/cil_resolve_ast.c
+++ b/libsepol/cil/src/cil_resolve_ast.c
@@ -2440,8 +2440,6 @@ int cil_resolve_in(struct cil_tree_node *current, void *extra_args)
 	}
 
 	cil_tree_children_destroy(current);
-	current->cl_head = NULL;
-	current->cl_tail = NULL;
 
 	return SEPOL_OK;
 
diff --git a/libsepol/cil/src/cil_tree.c b/libsepol/cil/src/cil_tree.c
index 75293005..075b1eb5 100644
--- a/libsepol/cil/src/cil_tree.c
+++ b/libsepol/cil/src/cil_tree.c
@@ -201,34 +201,21 @@ void cil_tree_subtree_destroy(struct cil_tree_node *node)
 
 void cil_tree_children_destroy(struct cil_tree_node *node)
 {
-	struct cil_tree_node *start_node = node;
-	struct cil_tree_node *next = NULL;
+	struct cil_tree_node *curr, *next;
 
-	if (node == NULL) {
+	if (!node) {
 		return;
 	}
 
-	if (node->cl_head != NULL) {
-		node = node->cl_head;
-	}
-
-	while (node != start_node) {
-		if (node->cl_head != NULL){
-			next = node->cl_head;
-		} else {
-			if (node->next == NULL) {
-				next = node->parent;
-				if (node->parent != NULL) {
-					node->parent->cl_head = NULL;
-				}
-				cil_tree_node_destroy(&node);
-			} else {
-				next = node->next;
-				cil_tree_node_destroy(&node);
-			}
-		}
-		node = next;
+	curr = node->cl_head;
+	while (curr) {
+		next = curr->next;
+		cil_tree_children_destroy(curr);
+		cil_tree_node_destroy(&curr);
+		curr = next;
 	}
+	node->cl_head = NULL;
+	node->cl_tail = NULL;
 }
 
 void cil_tree_node_init(struct cil_tree_node **node)
-- 
2.31.1




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux