From cd80bff8839d4afc1791f1458cad2f5bb01e2f61 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 4 Oct 2020 14:00:14 -0700 Subject: [PATCH] use a local instead of reusing global AF in gvrender_polyline There is a static global, AF, that is reused for a number of gvrender functions, but none need to retain previous data stored in this array. This hack presumably was from a time when allocators were much slower. Refactoring this into a local allocation makes this function thread safe and removes the need to unnecessarily prolong the lifetime of this allocation, thus decreasing Graphviz memory usage. This commit introduces a -Wshadow warning about AF, but that will be removed when we soon remove the static global. --- lib/gvc/gvrender.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index c5a858de5..bbbdbef32 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -646,12 +646,12 @@ void gvrender_polyline(GVJ_t * job, pointf * af, int n) if (job->flags & GVRENDER_DOES_TRANSFORM) gvre->polyline(job, af, n); else { - if (sizeAF < n) { - sizeAF = n + 10; - AF = grealloc(AF, sizeAF * sizeof(pointf)); - } + pointf *AF; + assert(n >= 0); + AF = gcalloc((size_t)n, sizeof(pointf)); gvrender_ptf_A(job, af, AF, n); gvre->polyline(job, AF, n); + free(AF); } } } -- 2.40.0