From ce6effe7da8f0450eff9e7ad21b9e8ec5e04d969 Mon Sep 17 00:00:00 2001 From: Emden Gansner Date: Thu, 21 Apr 2016 12:04:55 -0400 Subject: [PATCH] Fix parser so that it guarantees the precondition S = G = NULL and postcondition S = NULL and G is a valid graph on success and 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. --- lib/cgraph/grammar.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cgraph/grammar.y b/lib/cgraph/grammar.y index b43f493a9..2f3f807bb 100644 --- a/lib/cgraph/grammar.y +++ b/lib/cgraph/grammar.y @@ -95,8 +95,8 @@ static gstack_t *S; %% -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 */ ; -- 2.50.1