From: Emden Gansner Date: Wed, 21 Oct 2015 17:07:34 +0000 (-0400) Subject: Fix for bug 2575 - fix memory leak from parser error. X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0bcef927d5d8bde77942a7e8591e858bd1d23262;p=graphviz Fix for bug 2575 - fix memory leak from parser error. --- diff --git a/lib/cgraph/grammar.y b/lib/cgraph/grammar.y index 585df46b3..82b593170 100644 --- a/lib/cgraph/grammar.y +++ b/lib/cgraph/grammar.y @@ -64,6 +64,7 @@ static void applyattrs(void *obj); static void endgraph(void); static void endnode(void); static void endedge(void); +static void freestack(void); static char* concat(char*, char*); static char* concatPort(char*, char*); @@ -95,7 +96,7 @@ static gstack_t *S; %% graph : hdr body {endgraph();} - | error {if (G) {agclose(G); G = Ag_G_global = NIL(Agraph_t*);}} + | error {freestack(); if (G) {endgraph(); agclose(G); G = Ag_G_global = NIL(Agraph_t*);}} | /* empty */ ; @@ -571,6 +572,16 @@ static void closesubg() assert(subg); } +static void freestack() +{ + while (S) { + deletelist(&(S->nodelist)); + deletelist(&(S->attrlist)); + deletelist(&(S->edgelist)); + S = pop(S); + } +} + extern FILE *yyin; Agraph_t *agconcat(Agraph_t *g, void *chan, Agdisc_t *disc) {