comparison src/libpst.c @ 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 86078d0c2e9c
children cc8ee701f190
comparison
equal deleted inserted replaced
286:ea7b2e4f474f 287:0f0ccd29b0d7
3192 3192
3193 static void pst_free_id2(pst_id2_tree * head) { 3193 static void pst_free_id2(pst_id2_tree * head) {
3194 pst_id2_tree *t; 3194 pst_id2_tree *t;
3195 DEBUG_ENT("pst_free_id2"); 3195 DEBUG_ENT("pst_free_id2");
3196 while (head) { 3196 while (head) {
3197 if (head->child) pst_free_id2(head->child); 3197 pst_free_id2(head->child);
3198 t = head->next; 3198 t = head->next;
3199 free(head); 3199 free(head);
3200 head = t; 3200 head = t;
3201 } 3201 }
3202 DEBUG_RET(); 3202 DEBUG_RET();
3217 3217
3218 static void pst_free_desc (pst_desc_tree *head) { 3218 static void pst_free_desc (pst_desc_tree *head) {
3219 pst_desc_tree *t; 3219 pst_desc_tree *t;
3220 DEBUG_ENT("pst_free_desc"); 3220 DEBUG_ENT("pst_free_desc");
3221 while (head) { 3221 while (head) {
3222 while (head->child) { 3222 pst_free_desc(head->child);
3223 head = head->child;
3224 }
3225
3226 // point t to the next item
3227 t = head->next; 3223 t = head->next;
3228 if (!t && head->parent) { 3224 free(head);
3229 t = head->parent;
3230 t->child = NULL; // set the child to NULL so we don't come back here again!
3231 }
3232
3233 if (head) free(head);
3234 else DIE(("head is NULL"));
3235
3236 head = t; 3225 head = t;
3237 } 3226 }
3238 DEBUG_RET(); 3227 DEBUG_RET();
3239 } 3228 }
3240 3229