From: Matthew Fernandez Date: Wed, 28 Dec 2022 22:45:30 +0000 (-0800) Subject: fdpgen compoundEdges: fix memory leak X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a24cb62fbf4532b0a038bb9ee7a5a2b526e41595;p=graphviz fdpgen compoundEdges: fix memory leak When hitting either of the error conditions in the loop, the next iteration would be begun without clearing or freeing the object list. The next call to `objectList` would overwrite the still-allocated previous object list and it would be lost. --- diff --git a/lib/fdpgen/clusteredges.c b/lib/fdpgen/clusteredges.c index 1313c579b..06509eda0 100644 --- a/lib/fdpgen/clusteredges.c +++ b/lib/fdpgen/clusteredges.c @@ -85,15 +85,6 @@ static void freeObjlist(objlist * l) } } -/* resetObjlist: - * Reset objlist so it can be reused, using - * the same memory. - */ -static void resetObjlist(objlist * l) -{ - l->cnt = 0; -} - /* makeClustObs: * Create an obstacle corresponding to a cluster's bbox. */ @@ -258,7 +249,6 @@ int compoundEdges(graph_t * g, expand_t* pm, int edgetype) node_t *head; edge_t *e; edge_t *e0; - objlist *objl = NULL; vconfig_t *vconfig; int rv = 0; @@ -268,13 +258,14 @@ int compoundEdges(graph_t * g, expand_t* pm, int edgetype) if (n == head && ED_count(e)) { /* self arc */ makeSelfArcs(e, GD_nodesep(g)); } else if (ED_count(e)) { - objl = objectList(e, pm); + objlist *objl = objectList(e, pm); assert(objl->cnt <= INT_MAX); if (Plegal_arrangement(objl->obs, (int)objl->cnt)) { vconfig = Pobsopen(objl->obs, (int)objl->cnt); if (!vconfig) { agerr(AGWARN, "compoundEdges: could not construct obstacles - falling back to straight line edges\n"); rv = 1; + freeObjlist(objl); continue; } } @@ -290,6 +281,7 @@ int compoundEdges(graph_t * g, expand_t* pm, int edgetype) margin.x, margin.y, pm->x, pm->y); rv = 1; } + freeObjlist(objl); continue; } @@ -302,10 +294,9 @@ int compoundEdges(graph_t * g, expand_t* pm, int edgetype) assert(objl->cnt <= INT_MAX); makeSpline(e0, objl->obs, (int)objl->cnt, false); } - resetObjlist(objl); + freeObjlist(objl); } } } - freeObjlist(objl); return rv; }