]> granicus.if.org Git - graphviz/commitdiff
Fix for bug 2575 - fix memory leak from parser error.
authorEmden Gansner <emdenrg@google.com>
Wed, 21 Oct 2015 17:07:34 +0000 (13:07 -0400)
committerEmden Gansner <emdenrg@google.com>
Wed, 21 Oct 2015 17:07:34 +0000 (13:07 -0400)
lib/cgraph/grammar.y

index 585df46b32f7ce29fc0d76f084b509ac89ce142e..82b59317047cd12cfcc1b58fbe65cdd8a020b2b9 100644 (file)
@@ -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)
 {