void freeTreeNode(TreeNode n) { if(n->children) freeTreeNode(n->children); if(n->next) freeTreeNode(n->next); free(n); mallocbts-=(int)(sizeof(struct treenode)); return; }
/**** Local functions definitions. ****/ static TA_ValueTreeNode *allocTreeNode( TA_Libc *libHandle, TA_ValueTreeNode *parent, TA_String *string ) { TA_ValueTreeNode *node; TA_RetCode retCode; TA_StringCache *stringCache; stringCache = TA_GetGlobalStringCache( libHandle ); node = (TA_ValueTreeNode *)TA_Malloc( libHandle, sizeof( TA_ValueTreeNode ) ); if( !node ) return (TA_ValueTreeNode *)NULL; node->string = NULL; node->parent = NULL; node->child = TA_ListAlloc( libHandle ); if( !node->child ) { freeTreeNode( libHandle, node ); return NULL; } if( string ) { node->string = TA_StringDup( stringCache, string ); if( !node->string ) { freeTreeNode( libHandle, node ); return NULL; } } if( parent ) { retCode = TA_ListAddTail( parent->child, node ); if( retCode != TA_SUCCESS ) { freeTreeNode( libHandle, node ); return NULL; } node->parent = parent; } return node; }
void destroy(Tree t) { if(t->root) freeTreeNode(t->root); free(t); mallocbts-=(int)(sizeof(struct tree)); }
void tree_clear(TreeNode *l,int bFreeTarget){ TreeNode *t, *x; x= l->first_child; while (x){ t= x->next; freeTreeNode(x,bFreeTarget); x = t; } x->first_child = NULL; x->last_child = NULL; x->child_count = 0; }
void freeTreeNode(TreeNode *l,int bFreeTarget){ TreeNode *t, *x; x= l->first_child; while (x){ t= x->next; freeTreeNode(x,bFreeTarget); x = t; } if (bFreeTarget) free(l->data); free(l); }
void freeTree(Tree *t,int bFreeTarget){ if (t->root) freeTreeNode(t->root,bFreeTarget); free(t); }