changeset 287:0f0ccd29b0d7

use recursion to free a tree structure
author Carl Byington <carl@five-ten-sg.com>
date Tue, 24 May 2011 17:01:00 -0700
parents ea7b2e4f474f
children fa7fc1ac6385
files src/libpst.c
diffstat 1 files changed, 3 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/libpst.c	Tue May 24 16:29:41 2011 -0700
+++ b/src/libpst.c	Tue May 24 17:01:00 2011 -0700
@@ -3194,7 +3194,7 @@
     pst_id2_tree *t;
     DEBUG_ENT("pst_free_id2");
     while (head) {
-        if (head->child) pst_free_id2(head->child);
+        pst_free_id2(head->child);
         t = head->next;
         free(head);
         head = t;
@@ -3219,20 +3219,9 @@
     pst_desc_tree *t;
     DEBUG_ENT("pst_free_desc");
     while (head) {
-        while (head->child) {
-            head = head->child;
-        }
-
-        // point t to the next item
+        pst_free_desc(head->child);
         t = head->next;
-        if (!t && head->parent) {
-            t = head->parent;
-            t->child = NULL; // set the child to NULL so we don't come back here again!
-        }
-
-        if (head) free(head);
-        else      DIE(("head is NULL"));
-
+        free(head);
         head = t;
     }
     DEBUG_RET();