Help: Memory Leaks

Howard Butler hobu at IASTATE.EDU
Tue Sep 13 18:34:49 EDT 2005


Ned,

I've had the same experience that you have had with things leaking.  My 
drawing code was exactly the same as yours (minus the throwing when 
MapServer didn't return an image).  I was doing msFreeImage and msFreeMap, 
etc.  Things were still leaking all over the place.

To further confound things, I was running in a multi-threaded environment 
(in which MapServer was mostly well-behaved) that made it difficult for 
valgrind (and my inexperience with valgrind) to track down.  After a day or 
two of trying to trace things, I gave up.

Thanks to Norman pointing it out to me, fork() (CreateProcess() or variants 
on Windows) made my life so much easier.  When it came time to draw, I 
forked the process and returned the imageObj's bytes back to the parent 
through a pipe.  It wasn't the ideal solution, but MapForker (thanks for 
the name Sean) can really pump out the maps (I think it was 100+ per minute 
on below average hardware...most of the time in my scenario was waiting for 
WMS calls to come back).  And the leaks aren't an issue because the child 
process that did the drawing goes away once it returns the imageObj bytes back.

If you can't take that approach and start tracking down leaks, post them in 
a bug and cc me on it.  I'd like to help clean up some of the big leaks if 
we can find them.

Howard


At 04:32 PM 9/13/2005, Ned Harding wrote:

>I'm trying to work with MapServer and getting bunches of memory leaks.  I 
>presume I am doing something wrong.
>
>In particular there are a bunch of leaks I'm getting in msDrawMap:
>
>    Call Stack:
>     f:\vs70builds\3077\vc\crtbld\crt\src\strdup.c (48): _strdup
>     s:\3rdparty\gis\mapserver\mapoutput.c (464): msAllocOutputFormat
>     s:\3rdparty\gis\mapserver\mapoutput.c (735): msCloneOutputFormat
>     s:\3rdparty\gis\mapserver\mapoutput.c (694): msApplyOutputFormat
>     s:\3rdparty\gis\mapserver\maplegend.c (324): msDrawLegend
>     s:\3rdparty\gis\mapserver\maplegend.c (403): msEmbedLegend
>     s:\3rdparty\gis\mapserver\mapdraw.c (534): msDrawMap
>     s:\wrigley\plugins\wrigleyspatialpluginsengine\mapserver.cpp (423): 
> SRC::Wrigley::MapServerInterface::MakeMap
>
>The code calling msDrawMap looks like:
>
>                                 imageObj *pImage = msDrawMap(pMap);
>                                 if (!pImage)
>                                         throw 
> SRC::Error(msGetErrorObj()->message);
>                                 unsigned nStatus = msSaveImage(pMap, 
> pImage, pFile);
>                                 msFreeImage(pImage);
>
>Also, I'm getting leaks from msCleanup()!
>     s:\3rdparty\gis\mapserver\maperror.c (172): msGetErrorObj
>     s:\3rdparty\gis\mapserver\maperror.c (256): msResetErrorList
>     s:\3rdparty\gis\mapserver\maputil.c (1307): msCleanup
>     s:\wrigley\plugins\wrigleyspatialpluginsengine\mapserver.cpp (443): 
> SRC::Wrigley::MapServerInterface::MakeMap
>
>It seams that msCleanup creates an error object even if there wasn't 
>previously one and it doesn't clean it up.
>
>What am I doing wrong?  There about about 50 more leaks than this and this 
>is pruducing a single map.  I'm calling msFreeMap and msCleanup... Is 
>there something different I should be calling?
>
>
>Ned Harding
>Chief Technology Officer
>SRC - Extending the Reach of Micromarketing
>3825 Iris Ave Suite 150
>Boulder, CO 80303
>(303) 440-8896 x104
>
><http://www.extendthereach.com>http://www.extendthereach.com 
><http://www.extendthereach.com/>
>
>Technology in Action:
>
><http://www.DemographicsNow.com>http://www.DemographicsNow.com 
><http://www.demographicsnow.com/>



More information about the mapserver-dev mailing list