G = NULL on error. We need to clean the stack in all cases to prevent a small memory leak. Note that if S starts as NULL and is non-NULL at the end, then in G is non-NULL.
%%
-graph : hdr body {endgraph();}
- | error {freestack(); if (G) {endgraph(); agclose(G); G = Ag_G_global = NIL(Agraph_t*);}}
+graph : hdr body {freestack(); endgraph();}
+ | error {if (G) {freestack(); endgraph(); agclose(G); G = Ag_G_global = NIL(Agraph_t*);}}
| /* empty */
;