[geos-devel] is this a big leak?

David Blasby dblasby at refractions.net
Tue Sep 30 20:00:59 EDT 2003


Yuri,

Find attached a program that creates a bunch of multipolygons and unions 
them together.

It appears to leak memory quite quickly. Valgrind says:



==3035== 267096 bytes in 41 blocks are still reachable in loss record 14 
of 14
==3035==    at 0x40168BBF: malloc (vg_clientfuncs.c:103)
==3035==    by 0x804AECA: __default_alloc_template<true, 
0>::_S_chunk_alloc(unsigned int, int &) (/usr/include/g++-3/stl_alloc.h:490)
==3035==    by 0x804ACAB: __default_alloc_template<true, 
0>::_S_refill(unsigned int) (/usr/include/g++-3/stl_alloc.h:531)
==3035==    by 0x402D82FB: basic_string<char, string_char_traits<char>, 
__default_alloc_template<true, 0> >::replace(unsigned int, unsigned int, 
char const *, unsigned int) (/usr/include/g++-3/stl_alloc.h:332)
==3035==    by 0x402CE628: __static_initialization_and_destruction_0 
(/usr/include/g++-3/std/bastring.h:223)
==3035==    by 0x402CEAB1: 
geos::TopologyValidationError::TopologyValidationError(int, 
geos::Coordinate) (/usr/include/g++-3/stl_map.h:76)
==3035==    by 0x402D7424: (within /raid/local/lib/libgeos.so.1.0.0)
==3035==    by 0x4000CA20: _dl_init (dl-init.c:70)
==3035==    by 0x400012F0: (within /lib/ld-2.2.4.so)
==3035==
==3035== LEAK SUMMARY:
==3035==    definitely lost: 0 bytes in 0 blocks.
==3035==    possibly lost:   0 bytes in 0 blocks.
==3035==    still reachable: 267936 bytes in 54 blocks.
==3035==         suppressed: 0 bytes in 0 blocks.
==3035==

I assume this is a leak of some sort - its a bit of a funny leak.

dave
-------------- next part --------------
// g++ -g test6.cpp -I/usr/local/include/geos -lgeos; ./a.out
// g++ -g test6.cpp -I/usr/local/include/geos -lgeos ; valgrind --leak-check=yes --num-callers=10 ./a.out

#include "stdio.h"
#include "io.h"
#include "geom.h"

using namespace geos;

double global_offset = 0;
    PrecisionModel *pm= new PrecisionModel();
	GeometryFactory *geomFactory = new GeometryFactory( pm, -1);

//create a simple multi-polygon
// offset shift the polygon to the left <offset> units
// MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 10.0000000000000000 0.0000000000000000, 10.0000000000000000 10.0000000000000000, 0.0000000000000000 10.0000000000000000, 0.0000000000000000 0.0000000000000000), (2.0000000000000000 2.0000000000000000, 4.0000000000000000 2.0000000000000000, 4.0000000000000000 4.0000000000000000, 2.0000000000000000 4.0000000000000000, 2.0000000000000000 2.0000000000000000)))

Geometry *a(double offset)
{


	Geometry *g1, *g2 ;
    Coordinate *c;
    CoordinateList *cl;
    LinearRing *outerRing;
    vector<Geometry *> *innerRings=new vector<Geometry *>;


	LinearRing *innerRing;
    vector<Geometry *> *polys=new vector<Geometry *>;

	cl = new BasicCoordinateList(5);


	c = new Coordinate(0+offset, 0);
	cl->setAt( *c ,0);
	delete c;
	c = new Coordinate(10+offset, 0);
	cl->setAt( *c ,1);
	delete c;
	c = new Coordinate(10+offset, 10);
	cl->setAt( *c ,2);
	delete c;
	c = new Coordinate(0+offset, 10);
	cl->setAt( *c ,3);
	delete c;
	c = new Coordinate(0+offset, 0);
	cl->setAt( *c ,4);
	delete c;

	outerRing = (LinearRing*) geomFactory->createLinearRing(cl);


	cl = new BasicCoordinateList(5);


	c = new Coordinate(2+offset, 2);
	cl->setAt( *c ,0);
	delete c;
	c = new Coordinate(4+offset, 2);
	cl->setAt( *c ,1);
	delete c;
	c = new Coordinate(4+offset, 4);
	cl->setAt( *c ,2);
	delete c;
	c = new Coordinate(2+offset, 4);
	cl->setAt( *c ,3);
	delete c;
	c = new Coordinate(2+offset, 2);
	cl->setAt( *c ,4);
	delete c;

			innerRing = (LinearRing *) geomFactory->createLinearRing(cl);
			innerRings->push_back(innerRing);


	g1 = geomFactory->createPolygon(outerRing, innerRings);

	polys->push_back(g1);

	g2 = geomFactory->createMultiPolygon(polys);



	return g2;
}

//unions
//    aa  AND
//    a new geometry, which is the standard multipolygon translated to the right

Geometry *op(Geometry *aa)
{
	Geometry  *bb, *cc;


		bb = a(global_offset);
			//15 ==> leaks a lot
			//5  ==> leaks a constant amount
		global_offset += 15;

		cc = aa->Union(bb);
		delete aa;
		delete bb;

		return cc;

}


int main(int argC, char* argV[])
{
		Geometry *aa;

		aa = a(global_offset);

		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);
		aa = op(aa);

	string s= aa->toString();
	cout << "geom1 == "<<s << endl;


	delete aa;
	delete geomFactory;
	delete pm;
}




More information about the geos-devel mailing list