]> granicus.if.org Git - graphviz/commitdiff
Fix memory leak in make_map_internal
authorAlex Henrie <alexhenrie24@gmail.com>
Sat, 9 Jan 2021 09:02:07 +0000 (02:02 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 23 Jan 2021 23:51:14 +0000 (15:51 -0800)
cmd/gvmap/make_map.c

index 04a71aa4b3b84c53b064408db5ed3d2a1ca58de5..480cf9823436a71152867b1acd50b4b1c868f8b5 100644 (file)
@@ -1891,11 +1891,14 @@ int make_map_internal(int exclude_random, int include_OK_points,
     xran = MALLOC(sizeof(real)*(*nrandom + 4)*dim2);
     nz = 0;
     if (INCLUDE_OK_POINTS){
-      int *grouping2;
       nzok0 = nzok = *nrandom - 1;/* points that are within tolerance of real or artificial points */
-      grouping2 = MALLOC(sizeof(int)*(n + *nrandom));
-      memcpy(grouping2, grouping, sizeof(int)*n);
-      grouping = grouping2;
+      if (grouping == grouping0) {
+        int *grouping2 = MALLOC(sizeof(int)*(n + *nrandom));
+        memcpy(grouping2, grouping, sizeof(int)*n);
+        grouping = grouping2;
+      } else {
+        grouping = REALLOC(grouping, sizeof(int)*(n + *nrandom));
+      }
     }
     nn = n;