From: Matthew Fernandez Date: Sun, 15 Jan 2023 22:20:06 +0000 (-0800) Subject: common graph_init: fix memory leak X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5445c382962a4d2125d53b1a0103b6c35eb176c;p=graphviz common graph_init: fix memory leak Gitlab: #1950 --- diff --git a/lib/common/input.c b/lib/common/input.c index f40bc5103..1945aa709 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -638,9 +638,10 @@ void graph_init(graph_t * g, bool use_rankdir) /* reparseable input */ if ((p = agget(g, "postaction"))) { /* requires a graph wrapper for yyparse */ - char *buf = gmalloc(strlen("digraph { }") + strlen(p) + 1); - sprintf(buf,"%s { %s }",agisdirected(g)?"digraph":"graph",p); - agmemconcat(g, buf); + agxbuf buf = {0}; + agxbprint(&buf, "%s { %s }", agisdirected(g) ? "digraph" : "graph", p); + agmemconcat(g, agxbuse(&buf)); + agxbfree(&buf); } /* set this up fairly early in case any string sizes are needed */