[geos-devel] using CoordinateOperation::edit cause memory leaks

Sandro Santilli strk at keybit.net
Mon May 13 03:16:15 PDT 2013


Hi Tereza, could you include a full testcase, including caller ?

--strk;

On Wed, May 08, 2013 at 01:59:28PM +0200, Tereza Fiedlerová wrote:
> Hello,
> 
> I'm trying to edit Geometry using class CoordinateOperation. My
> implementation of CoordinateOperation::edit function looks like follows:
> 
> 
> CoordinateSequence* VertexGeometryEditorOperation::edit(const
> CoordinateSequence *, const Geometry *geom )
> {
>     CoordinateSequence* coord = geom->getCoordinates();
> 
>     for ( size_t i = 0; i < coord->getSize(); i++)
>     {
>             coord->setAt( closeCoord->getAt(i)+number, i );
>     }
> 
>     return coord;
> 
> }
> 
> Everything works fine, but when I check it with walgrind it returned these
> memory leaks:
> 
> ==19845== 168 bytes in 3 blocks are possibly lost in loss record 335 of 426
> ==19845==    at 0x4C2C154: operator new(unsigned long)
> (vg_replace_malloc.c:298)
> ==19845==    by 0xF206682:
> geos::geom::GeometryFactory::createLinearRing(geos::geom::CoordinateSequence*)
> const (GeometryFactory.cpp:411)
> ==19845==    by 0xF211A31:
> geos::geom::util::CoordinateOperation::edit(geos::geom::Geometry const*,
> geos::geom::GeometryFactory const*) (CoordinateOperation.cpp:38)
> ==19845==    by 0xF2123D6:
> geos::geom::util::GeometryEditor::editPolygon(geos::geom::Polygon const*,
> geos::geom::util::GeometryEditorOperation*) (GeometryEditor.cpp:117)
> ==19845==    by 0xF212273:
> geos::geom::util::GeometryEditor::edit(geos::geom::Geometry const*,
> geos::geom::util::GeometryEditorOperation*) (GeometryEditor.cpp:88)
> ==19845==    by 0xBFB30FE:
> geoc::alg::VertexSnapper::snapVertices(geoc::geo::GEOCGeom*,
> geos::geom::CoordinateSequence*) (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0xBFB33A1: geoc::alg::VertexSnapper::snap() (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0x566782E: QgsConflateProvider::vertexSnap() (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/qgsconflate/libqgsconflate.so.1.0.0)
> ==19845==    by 0x401C65: main (main.cpp:85)
> 
> ==19845== 192 bytes in 3 blocks are possibly lost in loss record 347 of 426
> ==19845==    at 0x4C2C154: operator new(unsigned long)
> (vg_replace_malloc.c:298)
> ==19845==    by 0xF206ACA:
> geos::geom::GeometryFactory::createPolygon(geos::geom::LinearRing*,
> std::vector<geos::geom::Geometry*, std::allocator<geos::geom::Geometry*>
> >*) const (GeometryFactory.cpp:525)
> ==19845==    by 0xF212568:
> geos::geom::util::GeometryEditor::editPolygon(geos::geom::Polygon const*,
> geos::geom::util::GeometryEditorOperation*) (GeometryEditor.cpp:144)
> ==19845==    by 0xF212273:
> geos::geom::util::GeometryEditor::edit(geos::geom::Geometry const*,
> geos::geom::util::GeometryEditorOperation*) (GeometryEditor.cpp:88)
> ==19845==    by 0xBFB30FE:
> geoc::alg::VertexSnapper::snapVertices(geoc::geo::GEOCGeom*,
> geos::geom::CoordinateSequence*) (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0xBFB33A1: geoc::alg::VertexSnapper::snap() (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0x566782E: QgsConflateProvider::vertexSnap() (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/qgsconflate/libqgsconflate.so.1.0.0)
> ==19845==    by 0x401C65: main (main.cpp:85)
> 
> 
> ==19845== 408 bytes in 3 blocks are possibly lost in loss record 382 of 426
> ==19845==    at 0x4C2C154: operator new(unsigned long)
> (vg_replace_malloc.c:298)
> ==19845==    by 0xF1FABE5:
> geos::geom::CoordinateArraySequence::CoordinateArraySequence(geos::geom::CoordinateArraySequence
> const&) (new_allocator.h:92)
> ==19845==    by 0xF1FACD8: geos::geom::CoordinateArraySequence::clone()
> const (CoordinateArraySequence.cpp:77)
> ==19845==    by 0xBFB7B6C:
> geoc::edit::VertexGeometryEditorOperation::edit(geos::geom::CoordinateSequence
> const*, geos::geom::Geometry const*) (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0xF211A26:
> geos::geom::util::CoordinateOperation::edit(geos::geom::Geometry const*,
> geos::geom::GeometryFactory const*) (CoordinateOperation.cpp:36)
> ==19845==    by 0xF2123D6:
> geos::geom::util::GeometryEditor::editPolygon(geos::geom::Polygon const*,
> geos::geom::util::GeometryEditorOperation*) (GeometryEditor.cpp:117)
> ==19845==    by 0xF212273:
> geos::geom::util::GeometryEditor::edit(geos::geom::Geometry const*,
> geos::geom::util::GeometryEditorOperation*) (GeometryEditor.cpp:88)
> ==19845==    by 0xBFB30FE:
> geoc::alg::VertexSnapper::snapVertices(geoc::geo::GEOCGeom*,
> geos::geom::CoordinateSequence*) (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0xBFB33A1: geoc::alg::VertexSnapper::snap() (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/geoc_cpp/libgeoc.so.1.0.0)
> ==19845==    by 0x566782E: QgsConflateProvider::vertexSnap() (in
> /host/Users/Tereza/Documents/CVUT-FSv/BP/src/qgsconflate/libqgsconflate.so.1.0.0)
> ==19845==    by 0x401C65: main (main.cpp:85)
> 
> ...
> 
> Anybody knows how to fix that?
> 
> Thanks,
> 
> Tereza


More information about the geos-devel mailing list