From 176c8a163a951a2b801956ed4a00da05603e3a06 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 25 Dec 2021 12:17:42 -0800 Subject: [PATCH] mingle bundle: avoid some manual memory management Note that this appears to actually fix a memory leak as `xx` was never freed previously. --- cmd/mingle/minglemain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/mingle/minglemain.cpp b/cmd/mingle/minglemain.cpp index 12caf5779..01ffc7742 100644 --- a/cmd/mingle/minglemain.cpp +++ b/cmd/mingle/minglemain.cpp @@ -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 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; -- 2.40.0