[GRASS5] [bug #869] (grass) Possible memory leak in src/libes/vect32/Vlib/get_area.c:Vect_get_area_points()

Eric G. Miller egm2 at jps.net
Tue Dec 11 21:06:52 EST 2001


On Tue, 11 Dec 2001 22:57:23 +0100 (CET), Request Tracker <grass-bugs at intevation.de> wrote:

> this bug's URL: http://intevation.de/rt/webrt?serial_num=869
> -------------------------------------------------------------------------
> 
> Subject: Possible memory leak in src/libes/vect32/Vlib/get_area.c:Vect_get_area_points()
[snip]
> 
>   The problem is the code
> 
> --
>   BPoints->n_points = 0;
>   BPoints->alloc_points = 0;
>   Area =  &(Map->Area[area]) ;
> --
> 
> in Vect_get_area_points(), if I replace it by
> 
> --
>   G_free(BPoints->x);
>   G_free(BPoints->y);
>   BPoints->n_points = 0;
>   BPoints->alloc_points = 0;
>   Area =  &(Map->Area[area]) ;
> --
> 
> the problem seens to go away.
> 
>   I am testing it with maps with more than 64k polygons, and with the patch,
> memory usage seens constant, when running the sample GrassDisplayVector
> function several times. I believe a better aproach should be done to fix
> the problem, as it is not really required to free the memory to just
> reallocate it in the code below, but I preferred to not change the logic
> of the code in the sample fix.

Yes, I think your correct about the memory leak.  The code should not assume
the line_struct is empty when it gets it.  I think you're also correct that
the right way to handle this is to use realloc() (if necessary) rather than
using free, as it could improve performance a little (especially when no
new memory is needed).

-- 
Eric G. Miller <egm2 at jps.net>



More information about the grass-dev mailing list