From: Matthew Fernandez Date: Sun, 3 Jan 2021 18:31:22 +0000 (-0800) Subject: fix: stop manually managing kdTree memory in mingle X-Git-Tag: 2.47.0~86^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c4bde8f60fd6de34f2ce31aea514b3580225303a;p=graphviz fix: stop manually managing kdTree memory in mingle This actually fixes a bug where the first kdTree allocation was being leaked due to never being deleted. Related to #1832. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index d8fe2a61f..64a5933d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - typos in gpcanvas.c #1927 +- memory leak in libmingle ## [2.46.0] - 2021-02-13 diff --git a/lib/mingle/nearest_neighbor_graph_ann.cpp b/lib/mingle/nearest_neighbor_graph_ann.cpp index 173d177f1..71e6488f2 100644 --- a/lib/mingle/nearest_neighbor_graph_ann.cpp +++ b/lib/mingle/nearest_neighbor_graph_ann.cpp @@ -88,7 +88,6 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, */ ANNpointArray dataPts; // data points - ANNkd_tree* kdTree; // search structure double *xx; int *irn, *jcn; @@ -112,12 +111,12 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, //========= graph when sort based on x ======== nz = 0; sortPtsX(nPts, dataPts); - kdTree = new ANNkd_tree( // build search structure + ANNkd_tree kdTree( // build search structure dataPts, // the data points nPts, // number of points dim); // dimension of space for (int ip = 0; ip < nPts; ip++){ - kdTree->annkSearch( // search + kdTree.annkSearch( // search dataPts[ip], // query point k, // number of near neighbors nnIdx.data(), // nearest neighbors (returned) @@ -140,12 +139,12 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, //========= graph when sort based on y ======== sortPtsY(nPts, dataPts); - kdTree = new ANNkd_tree( // build search structure + kdTree = ANNkd_tree( // build search structure dataPts, // the data points nPts, // number of points dim); // dimension of space for (int ip = 0; ip < nPts; ip++){ - kdTree->annkSearch( // search + kdTree.annkSearch( // search dataPts[ip], // query point k, // number of near neighbors nnIdx.data(), // nearest neighbors (returned) @@ -161,8 +160,6 @@ void nearest_neighbor_graph_ann(int nPts, int dim, int k, double eps, double *x, } } - delete kdTree; // clean things up - *nz0 = nz; annClose(); // done with ANN