Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99f02d4

Browse files
committed
Free parse tree when deleting parser.
1 parent f127027 commit 99f02d4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Parser/parser.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ newparser(g, start)
9696
ps->p_grammar = g;
9797
ps->p_tree = newnode(start);
9898
if (ps->p_tree == NULL) {
99-
if (ps->p_tree != NULL)
100-
DEL(ps->p_tree); /* XXX freeing a node!?! */
10199
DEL(ps);
102100
return NULL;
103101
}
@@ -110,6 +108,9 @@ void
110108
delparser(ps)
111109
parser_state *ps;
112110
{
111+
/* NB If you want to save the parse tree,
112+
you must set p_tree to NULL before calling delparser! */
113+
freenode(ps->p_tree);
113114
DEL(ps);
114115
}
115116

0 commit comments

Comments
 (0)