From 966b40288149e49be78f16a6e245a797c929238f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 31 Jan 2009 02:30:28 +0000 Subject: urldb_destroy_path_tree() -> iteration svn path=/trunk/netsurf/; revision=6315 --- content/urldb.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/content/urldb.c b/content/urldb.c index 4dec77dad..2f0ff6533 100644 --- a/content/urldb.c +++ b/content/urldb.c @@ -3864,17 +3864,32 @@ void urldb_destroy_host_tree(struct host_part *root) */ void urldb_destroy_path_tree(struct path_data *root) { - struct path_data *p, *q; + struct path_data *p = root; - /* Destroy children */ - for (p = root->children; p; p = q) { - q = p->next; - urldb_destroy_path_tree(p); - } + do { + if (p->children != NULL) { + p = p->children; + } else { + struct path_data *q = p; - /* And ourselves */ - urldb_destroy_path_node_content(root); - free(root); + while (p != root) { + if (p->next != NULL) { + p = p->next; + break; + } + + p = p->parent; + + urldb_destroy_path_node_content(q); + free(q); + + q = p; + } + + urldb_destroy_path_node_content(q); + free(q); + } + } while (p != root); } /** -- cgit v1.2.3