Skip to content

Commit

Permalink
Prepared geometry predicate exception memory leak (#506)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Baston <dbaston@gmail.com>
  • Loading branch information
brendan-ward and dbaston committed Nov 23, 2021
1 parent 8455871 commit 22b5f61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/geomgraph/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <geos/util.h>

#include <cmath>
#include <memory>
#include <string>
#include <sstream>
#include <vector>
Expand Down Expand Up @@ -132,8 +133,9 @@ Node::isIncidentEdgeInResult() const
}

void
Node::add(EdgeEnd* e)
Node::add(EdgeEnd* p_e)
{
std::unique_ptr<EdgeEnd> e(p_e);
assert(e);
#if GEOS_DEBUG
std::cerr << "[" << this << "] Node::add(" << e->print() << ")" << std::endl;
Expand All @@ -152,10 +154,10 @@ Node::add(EdgeEnd* e)
assert(edges);
//if (edges==NULL) return;

edges->insert(e);
e->setNode(this);
edges->insert(e.release());
p_e->setNode(this);
#if COMPUTE_Z
addZ(e->getCoordinate().z);
addZ(p_e->getCoordinate().z);
#endif
testInvariant();
}
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/capi/GEOSPreparedGeometryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,23 @@ void object::test<13>
ensure_equals(ret, 0);
}

// Verify no memory leak on exception (https://github.com/libgeos/geos/issues/505)
template<>
template<>
void object::test<14>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 1 NaN)");
geom2_ = GEOSGeomFromWKT("POINT(0 0)");
prepGeom1_ = GEOSPrepare(geom1_);

ensure(nullptr != prepGeom1_);
ensure(nullptr != geom2_);

int ret = GEOSPreparedTouches(prepGeom1_, geom2_);
ensure_equals(ret, 2);
}


} // namespace tut

0 comments on commit 22b5f61

Please sign in to comment.