]> granicus.if.org Git - graphviz/commitdiff
use a local instead of reusing global AF in gvrender_beziercurve
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 4 Oct 2020 20:47:27 +0000 (13:47 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Oct 2020 21:45:05 +0000 (14:45 -0700)
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

index 0cc0a4b6a6c5dba61acab8769a6bbc27caa7e025..c5a858de5ad3bfd9a6a1a3a6c73ce59182ce386f 100644 (file)
@@ -625,13 +625,13 @@ void gvrender_beziercurve(GVJ_t * job, pointf * af, int n,
                gvre->beziercurve(job, af, n, arrow_at_start, arrow_at_end,
                                  filled);
            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->beziercurve(job, AF, n, arrow_at_start, arrow_at_end,
                                  filled);
+               free(AF);
            }
        }
     }