]> granicus.if.org Git - graphviz/commitdiff
common graph_init: fix memory leak
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 15 Jan 2023 22:20:06 +0000 (14:20 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 21 Jan 2023 04:48:33 +0000 (20:48 -0800)
Gitlab: #1950

lib/common/input.c

index f40bc510392640f19b03458cee4969228b8851d2..1945aa709f8392e5c05ba01d64e979cece14e8c3 100644 (file)
@@ -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 */