[postgis-devel] fix for memory leaks in shp2pgsql.c

Mark Cave-Ayland mark.cave-ayland at siriusit.co.uk
Wed Oct 14 01:38:06 PDT 2009


Dave Fuhry wrote:

> Paul,
> 
>    1.4.0.
> 
>    I originally hit the problem on 1.3.x, then patched 1.4.0, which
> I'm /pretty/ sure was exhibiting the problem.
> 
>    It was easy to see in `top` that shp2pgsql was gorging on memory as
> execution continued, and the leak locations were revealed fairly
> clearly in `valgrind --leak-check=full`.  This work is all against
> polygons; my impression is that loading of points or linestrings is
> unaffected.
> 
> -Dave


Hi Dave,

Thanks for the investigation and patch. In terms of the 1.4 shp2pgsql 
then it appears the leak is my fault, as I forgot that since I used a 
dangling pointer for the ring point lists then I manually need to free 
them within the structure afterwards. Oops.

I'd like to re-work the patch a little rather than applying it as is - 
for example, it explicitly sets unused references to NULL which is not 
necessary in C (as opposed to a language such as Java).

In terms of the 1.3 shp2pgsql then I'm not sure that it's the same leak, 
since most of the old shp2pgsql got blown away with the conversion to 
liblwgeom...


ATB,

Mark.

-- 
Mark Cave-Ayland - Senior Technical Architect
PostgreSQL - PostGIS
Sirius Corporation plc - control through freedom
http://www.siriusit.co.uk
t: +44 870 608 0063

Sirius Labs: http://www.siriusit.co.uk/labs



More information about the postgis-devel mailing list