Skip to content

Commit

Permalink
Fix memory leak in IndexedFacetDistance
Browse files Browse the repository at this point in the history
Patch by Dan Baston (see #795)

git-svn-id: http://svn.osgeo.org/geos/trunk@4300 5242fede-7e19-0410-aef8-94bd7d2200fb
  • Loading branch information
strk committed Oct 31, 2016
1 parent 24ea7e6 commit b7943e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/geos/operation/distance/IndexedFacetDistance.h
Expand Up @@ -34,6 +34,8 @@ namespace geos {

double getDistance(const geom::Geometry * g) const;

~IndexedFacetDistance();

private:
std::auto_ptr<geos::index::strtree::STRtree> cachedTree;

Expand Down
17 changes: 16 additions & 1 deletion src/operation/distance/IndexedFacetDistance.cpp
Expand Up @@ -18,13 +18,20 @@

#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;

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);
Expand All @@ -41,7 +48,15 @@ namespace geos {

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);
}
}
}
Expand Down

0 comments on commit b7943e7

Please sign in to comment.