[geos-commits] r4300 - in trunk: include/geos/operation/distance src/operation/distance

Sandro Santilli strk at kbt.io
Mon Oct 31 15:27:50 PDT 2016


Author: strk
Date: 2016-10-31 15:27:50 -0700 (Mon, 31 Oct 2016)
New Revision: 4300

Modified:
   trunk/include/geos/operation/distance/IndexedFacetDistance.h
   trunk/src/operation/distance/IndexedFacetDistance.cpp
Log:
Fix memory leak in IndexedFacetDistance

Patch by Dan Baston (see #795)

Modified: trunk/include/geos/operation/distance/IndexedFacetDistance.h
===================================================================
--- trunk/include/geos/operation/distance/IndexedFacetDistance.h	2016-10-28 15:37:41 UTC (rev 4299)
+++ trunk/include/geos/operation/distance/IndexedFacetDistance.h	2016-10-31 22:27:50 UTC (rev 4300)
@@ -34,6 +34,8 @@
 
                 double getDistance(const geom::Geometry * g) const;
 
+                ~IndexedFacetDistance();
+
             private:
                 std::auto_ptr<geos::index::strtree::STRtree> cachedTree;
 

Modified: trunk/src/operation/distance/IndexedFacetDistance.cpp
===================================================================
--- trunk/src/operation/distance/IndexedFacetDistance.cpp	2016-10-28 15:37:41 UTC (rev 4299)
+++ trunk/src/operation/distance/IndexedFacetDistance.cpp	2016-10-31 22:27:50 UTC (rev 4300)
@@ -18,6 +18,7 @@
 
 #include <geos/index/strtree/STRtree.h>
 #include <geos/operation/distance/IndexedFacetDistance.h>
+#include <geos/index/ItemVisitor.h>
 
 using namespace geos::geom;
 using namespace geos::index::strtree;
@@ -25,6 +26,12 @@
 namespace geos {
     namespace operation {
         namespace distance {
+            struct : public index::ItemVisitor {
+                void visitItem(void * item) {
+                    delete static_cast<FacetSequence*>(item);
+                }
+            } deleter;
+
             double IndexedFacetDistance::distance(const Geometry * g1, const Geometry * g2) {
                 IndexedFacetDistance ifd(g1);
                 return ifd.getDistance(g2);
@@ -41,8 +48,16 @@
 
                 std::pair<const void*, const void*> obj = cachedTree->nearestNeighbour(tree2.get(), dynamic_cast<ItemDistance*>(&itemDistance));
 
-                return static_cast<const FacetSequence*>(obj.first)->distance(*static_cast<const FacetSequence*>(obj.second));
+                double distance = static_cast<const FacetSequence*>(obj.first)->distance(*static_cast<const FacetSequence*>(obj.second));
+
+                tree2->iterate(deleter);
+
+                return distance;
             }
+
+            IndexedFacetDistance::~IndexedFacetDistance() {
+                cachedTree->iterate(deleter);
+            }
         }
     }
 }



More information about the geos-commits mailing list