]> granicus.if.org Git - graphviz/commitdiff
mingle bundle: avoid some manual memory management
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 25 Dec 2021 20:17:42 +0000 (12:17 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 4 Jan 2022 15:58:22 +0000 (07:58 -0800)
Note that this appears to actually fix a memory leak as `xx` was never freed
previously.

cmd/mingle/minglemain.cpp

index 12caf5779b0fe3b7920f51cb5fa1a3774a77f58d..01ffc774272880f5e5d92fdcd8c2efa7db57e84f 100644 (file)
@@ -376,7 +376,7 @@ bundle (Agraph_t* g, opts_t* opts)
        SparseMatrix A;
        SparseMatrix B;
        pedge* edges;
-    double *xx, eps = 0.;
+    double eps = 0.;
     int nz = 0;
     int *ia, *ja, i, j, k;
        int rv = 0;
@@ -435,7 +435,7 @@ bundle (Agraph_t* g, opts_t* opts)
                
        ia = A->ia; ja = A->ja;
        nz = A->nz;
-       xx = (double*)MALLOC(sizeof(double) * nz * 4);
+       std::unique_ptr<double[]> xx(new double[nz * 4]);
        nz = 0;
        dim = 4;
        for (i = 0; i < A->m; i++){
@@ -452,12 +452,12 @@ bundle (Agraph_t* g, opts_t* opts)
        if (Verbose)
                fprintf(stderr,"n = %d nz = %d\n",A->m, nz);
 
-       B = nearest_neighbor_graph(nz, MIN(opts->nneighbors, nz), xx, eps);
+       B = nearest_neighbor_graph(nz, MIN(opts->nneighbors, nz), xx.get(), eps);
 
        SparseMatrix_delete(A);
        A = B;
        free(x);
-       x = xx;
+       x = xx.get();
 
        dim = 2;