[geos-commits] r3465 - in trunk: src/algorithm tests/unit
tests/unit/algorithm
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon Sep 12 03:47:39 EDT 2011
Author: strk
Date: 2011-09-12 00:47:39 -0700 (Mon, 12 Sep 2011)
New Revision: 3465
Added:
trunk/tests/unit/algorithm/InteriorPointAreaTest.cpp
Modified:
trunk/src/algorithm/InteriorPointArea.cpp
trunk/tests/unit/Makefile.am
Log:
Fix memory leak on invalid geometry in InteriorPointArea (#475)
Modified: trunk/src/algorithm/InteriorPointArea.cpp
===================================================================
--- trunk/src/algorithm/InteriorPointArea.cpp 2011-09-12 07:39:19 UTC (rev 3464)
+++ trunk/src/algorithm/InteriorPointArea.cpp 2011-09-12 07:47:39 UTC (rev 3465)
@@ -1,9 +1,9 @@
/**********************************************************************
- * $Id$
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net>
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
@@ -26,6 +26,7 @@
#include <vector>
#include <typeinfo>
+#include <memory> // for auto_ptr
using namespace std;
using namespace geos::geom;
@@ -88,19 +89,16 @@
void
InteriorPointArea::addPolygon(const Geometry *geometry)
{
- LineString *bisector=horizontalBisector(geometry);
- Geometry *intersections=bisector->intersection(geometry);
- const Geometry *widestIntersection=widestGeometry(intersections);
- const Envelope *env=widestIntersection->getEnvelopeInternal();
- double width=env->getWidth();
- if (!foundInterior || width>maxWidth) {
- env->centre(interiorPoint);
- maxWidth = width;
- foundInterior=true;
- }
- //delete env;
- delete bisector;
- delete intersections;
+ auto_ptr<LineString> bisector ( horizontalBisector(geometry) );
+ auto_ptr<Geometry> intersections ( bisector->intersection(geometry) );
+ const Geometry *widestIntersection = widestGeometry(intersections.get());
+ const Envelope *env = widestIntersection->getEnvelopeInternal();
+ double width=env->getWidth();
+ if (!foundInterior || width>maxWidth) {
+ env->centre(interiorPoint);
+ maxWidth = width;
+ foundInterior=true;
+ }
}
//@return if geometry is a collection, the widest sub-geometry; otherwise,
@@ -148,12 +146,9 @@
(*cv)[1].x = envelope->getMaxX();
(*cv)[1].y = avgY;
- //delete envelope;
-
CoordinateSequence *cl = factory->getCoordinateSequenceFactory()->create(cv);
LineString *ret = factory->createLineString(cl);
- //delete cl;
return ret;
}
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2011-09-12 07:39:19 UTC (rev 3464)
+++ trunk/tests/unit/Makefile.am 2011-09-12 07:47:39 UTC (rev 3465)
@@ -32,6 +32,7 @@
geos_unit_SOURCES = \
geos_unit.cpp \
algorithm/AngleTest.cpp \
+ algorithm/InteriorPointAreaTest.cpp \
algorithm/CGAlgorithms/isCCWTest.cpp \
algorithm/CGAlgorithms/isPointInRingTest.cpp \
algorithm/CGAlgorithms/computeOrientationTest.cpp \
Added: trunk/tests/unit/algorithm/InteriorPointAreaTest.cpp
===================================================================
--- trunk/tests/unit/algorithm/InteriorPointAreaTest.cpp (rev 0)
+++ trunk/tests/unit/algorithm/InteriorPointAreaTest.cpp 2011-09-12 07:47:39 UTC (rev 3465)
@@ -0,0 +1,84 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2011 Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+//
+// Test Suite for geos::algorithm::InteriorPointArea
+
+#include <tut.hpp>
+// geos
+#include <geos/geom/Coordinate.h>
+#include <geos/algorithm/InteriorPointArea.h>
+#include <geos/io/WKTReader.h>
+#include <geos/geom/Geometry.h>
+// std
+#include <sstream>
+#include <string>
+#include <memory>
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // dummy data, not used
+ struct test_interiorpointarea_data {
+ typedef geos::geom::Geometry Geometry;
+ typedef geos::geom::Coordinate Coordinate;
+ typedef geos::algorithm::InteriorPointArea InteriorPointArea;
+
+ geos::io::WKTReader reader;
+ std::auto_ptr<Geometry> geom;
+
+ test_interiorpointarea_data()
+ {}
+
+ };
+
+ typedef test_group<test_interiorpointarea_data> group;
+ typedef group::object object;
+
+ group test_interiorpointarea_group("geos::algorithm::InteriorPointArea");
+
+ //
+ // Test Cases
+ //
+
+ // http://trac.osgeo.org/geos/ticket/475
+ // This is a test for a memory leak more than anything else
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ Coordinate centroid;
+
+ // this polygon is a typical hourglass-shape with a self intersection
+ // without a node
+ geom.reset( reader.read("POLYGON((6 54, 15 54, 6 47, 15 47, 6 54))") );
+
+ bool threw = false;
+
+ try {
+ InteriorPointArea interior_builder(geom.get());
+ interior_builder.getInteriorPoint(centroid);
+ }
+ catch(...) {
+ threw = true;
+ }
+
+ ensure(threw);
+ }
+
+} // namespace tut
+
More information about the geos-commits
mailing list