]> granicus.if.org Git - graphviz/commitdiff
fix: stop manually managing kdTree memory in mingle
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 3 Jan 2021 18:31:22 +0000 (10:31 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 14 Feb 2021 03:14:46 +0000 (19:14 -0800)
This actually fixes a bug where the first kdTree allocation was being leaked due
to never being deleted. Related to #1832.

CHANGELOG.md
lib/mingle/nearest_neighbor_graph_ann.cpp

index d8fe2a61f9416ba751d4e156f9002676181f4157..64a5933d9c13625607ca2f1790e9b2d99939ddf5 100644 (file)
@@ -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
 
index 173d177f1e407eff8b8401f535b5079d60aa6d53..71e6488f2a33587d3534648846a10534dbb8ee9c 100644 (file)
@@ -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