]> granicus.if.org Git - graphviz/commitdiff
agglomerative_ink_bundling_internal: remove 'xx' manual memory management
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 15 Jan 2022 22:13:52 +0000 (14:13 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 16 Jan 2022 18:51:42 +0000 (10:51 -0800)
lib/mingle/agglomerative_bundling.cpp

index d09917dd911a723237af9212ae85ddea73b8b460..247f334fe8d236fb1d6d5e40629f0cea9c0617bd 100644 (file)
@@ -391,7 +391,6 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge
     }
   } else {
     pedge *mid_edges, midedge;/* middle section of edges that will be bundled again */
-    double *xx;
     int ne, npp, l;
     SparseMatrix A_mid;
     double eps = 0., wgt, total_wgt = 0;
@@ -409,7 +408,7 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge
     ja = R->ja;
     ne = R->m;
     mid_edges = (pedge*)MALLOC(sizeof(pedge)*ne);
-    xx = (double*)MALLOC(sizeof(double)*4*ne);
+    std::vector<double> xx(4 * ne);
     for (i = 0; i < R->m; i++){
       pick = &(ja[ia[i]]);
       wgt = 0.;
@@ -424,14 +423,13 @@ static pedge* agglomerative_ink_bundling_internal(int dim, SparseMatrix A, pedge
       xx[i*4 + 1] = meet1.y;
       xx[i*4 + 2] = meet2.x;
       xx[i*4 + 3] = meet2.y;
-      mid_edges[i] = pedge_wgt_new(2, dim, &(xx[i*4]), wgt);
+      mid_edges[i] = pedge_wgt_new(2, dim, &xx.data()[i*4], wgt);
     }
 
-    A_mid = nearest_neighbor_graph(ne, MIN(nneighbors, ne), xx, eps);
+    A_mid = nearest_neighbor_graph(ne, MIN(nneighbors, ne), xx.data(), eps);
 
     agglomerative_ink_bundling_internal(dim, A_mid, mid_edges, nneighbors, recurse_level, MAX_RECURSE_LEVEL, angle_param, angle, open_gl, current_ink, ink00, flag);
     SparseMatrix_delete(A_mid);
-    free(xx);
     
     /* patching edges with the new mid-section */
     for (i = 0; i < R->m; i++){