msSHPReadShape and potential memory leak (and sorthshp.c)

Frank Warmerdam fwarmerdam at GMAIL.COM
Mon Jul 11 10:45:35 EDT 2005


On 7/10/05, Richard Roger <richard.roger at agric.nsw.gov.au> wrote:

> This memory "leak" in the first loop is caused by my initially poor
> understanding and use of msSHPReadShape, but I think it's a mistake others
> might easily make.  I think this "feature" could be avoided by the following
> change : 
>  
> *** replace the call to "msInitShape" in "msSHPReadShape" by a call to a
> "msFreeShape". 
>  
> I am not sure if "msFreeShape" would need to be modified to deal with an
> entirely null shape. 

Richard, 

The problem is that msSHPReadShape() is typically used with shapeObj's
allocated on the stack, but these are not initialized to any dependable
value.  So msSHPReadShape() has no way of telling if the shapeObj
fields have pointers that need to be freed, or are just unitialized
values pointing into hyperspace. 

So, I don't really think there is much we can practically do to change
things ... we just need to be careful.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the mapserver-dev mailing list