From: Matthew Fernandez Date: Sat, 14 Nov 2020 20:04:38 +0000 (-0800) Subject: remove use of longjmp() in add_tree_edge() X-Git-Tag: 2.46.1~31^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e00efc8729718e1758cf41a901dea16f74326a3;p=graphviz remove use of longjmp() in add_tree_edge() This also fixes some resource leaks that occurred in this path. The longjmp() would jump over some intermediate allocations that had been made, whereas we now return back through the callers, cleaning up resources as we go. Related to #1801. --- diff --git a/lib/common/ns.c b/lib/common/ns.c index 1cc03210e..5dc5a1df3 100644 --- a/lib/common/ns.c +++ b/lib/common/ns.c @@ -48,7 +48,7 @@ static int add_tree_edge(edge_t * e) //fprintf(stderr,"add tree edge %p %s ", (void*)e, agnameof(agtail(e))) ; fprintf(stderr,"%s\n", agnameof(aghead(e))) ; if (TREE_EDGE(e)) { agerr(AGERR, "add_tree_edge: missing tree edge\n"); - longjmp (jbuf, 1); + return -1; } ED_tree_index(e) = Tree_edge.size; Tree_edge.list[Tree_edge.size++] = e; @@ -62,7 +62,7 @@ static int add_tree_edge(edge_t * e) ND_tree_out(n).list[ND_tree_out(n).size] = NULL; if (ND_out(n).list[ND_tree_out(n).size - 1] == 0) { agerr(AGERR, "add_tree_edge: empty outedge list\n"); - longjmp (jbuf, 1); + return -1; } n = aghead(e); ND_mark(n) = TRUE; @@ -70,7 +70,7 @@ static int add_tree_edge(edge_t * e) ND_tree_in(n).list[ND_tree_in(n).size] = NULL; if (ND_in(n).list[ND_tree_in(n).size - 1] == 0) { agerr(AGERR, "add_tree_edge: empty inedge list\n"); - longjmp (jbuf, 1); + return -1; } return 0; }