[Mapserver-dev] [PATCH] mapraster.c - fixing memory leaks

Stephen Woodbridge woodbri at swoodbridge.com
Tue Jun 15 21:01:54 EDT 2004


While I have done an development in mapserver, I think limited use of 
goto's is fine especially if it makes the code cleaner and more 
readable. This is a good thing. This is often the case when you want to 
bailout of highly nested code and need to do cleanup. Too often an error 
is thrown and a return is done with no free()ing of appropriate stuff.

You have my vote.
   -Steve W.

Steve Lime wrote:

> Patch aside, what do folks think about using goto's? They seem a great
> help with things like clean-up. However there's not one in the code
> presently so I was wondering if there's a bias...
> 
> Steve
> 
> Stephen Lime
> Data & Applications Manager
> 
> Minnesota DNR
> 500 Lafayette Road
> St. Paul, MN 55155
> 651-297-2937
> 
>>>>"Mladen Turk" <mturk at apache.org> 06/02/04 11:18 AM >>>
> 
> 
> Hi all,
> 
> Mapraster has a memory leak bug not freeing allocated temporary layer. 
> The quickest solution would be to just add the tlptemp variable, but
> I've
> added standard 'cleanup:' label for function exiting. 
> 
> Having something like mpatrol gives:
> 
>                 Total unfreed bytes:        92899
>                 Peak memory usage:        1699139
>                 Largest allocation:        235750
>                 Smallest allocation:            1
>                 Total Allocations:            513
>                 Total Frees:                  505
>                 Peak Allocations:             385
> 
> 
> The patch for mapraster.c gives:
> 
>                 Total unfreed bytes:           14
>                 Peak memory usage:        1699139
>                 Largest allocation:        235750
>                 Smallest allocation:            1
>                 Total Allocations:            513
>                 Total Frees:                  512
>                 Peak Allocations:             385
> 
> So we've save cca 92K of memory on each request.
> 
> Here is the patch:
> (I can file a bug report if needed)
> 
> There is still 14 bytes left hanging but the reason is in the
> getString()
> from mapfile.c used somewhere :). I'll try to hunt that down.
> 
> MT.
> 
> _______________________________________________
> Mapserver-dev mailing list
> Mapserver-dev at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-dev
> 




More information about the mapserver-dev mailing list