[GRASS-dev] Possible memory leak in G__open_cell_old in opencell.c

Hi,

I am debugging my code to find memory leak. I have a memory leak that I am not able to find. Is it possible that there is a memory leak in the function G__open_cell_old declared in opencell.c?

It is the first time that I deal with the gis library code so please forgive me if I misunderstand the code.
I do not understand why the variable gdal is not freed at the end of the function.

Thank you for you time,
Matteo

On Fri, Mar 15, 2013 at 3:45 PM, matteo poletti <pollo1_91@yahoo.it> wrote:

Hi,

I am debugging my code to find memory leak. I have a memory leak that I am not able to find. Is it possible that there is a memory leak in the function G__open_cell_old declared in opencell.c?

It is the first time that I deal with the gis library code so please forgive me if I misunderstand the code.
I do not understand why the variable gdal is not freed at the end of the function.

Which GRASS 6 version are you using, from SVN?

Maybe useful:
http://grasswiki.osgeo.org/wiki/GRASS_Debugging#Using_Valgrind
to get a more precise idea.

Markus

Da: Markus Neteler <neteler@osgeo.org>

I do not understand why the variable gdal is not freed at the end of the

function.

Which GRASS 6 version are you using, from SVN?

I'm referring to this code http://grass.osgeo.org/programming6/opencell_8c_source.html, line 149.

Matteo

matteo poletti wrote:

I am debugging my code to find memory leak. I have a memory leak
that I am not able to find. Is it possible that there is a memory
leak in the function G__open_cell_old declared in opencell.c?

It is the first time that I deal with the gis library code so please
forgive me if I misunderstand the code.

I do not understand why the variable gdal is not freed at the end of
the function.

Because it's "owned" by the fileinfo structure; line 311:

  fcb->gdal = gdal;

The structure is freed on line 131 of closecell.c:

130 if (fcb->gdal)
131 G_close_gdal_link(fcb->gdal);

http://grass.osgeo.org/programming6/closecell_8c_source.html#l00130

--
Glynn Clements <glynn@gclements.plus.com>

Da: Glynn Clements <glynn@gclements.plus.com>

I am debugging my code to find memory leak. I have a memory leak
that I am not able to find. Is it possible that there is a memory
leak in the function G__open_cell_old declared in opencell.c?

Because it's "owned" by the fileinfo structure; line 311:

fcb\-&gt;gdal = gdal;

The structure is freed on line 131 of closecell.c:

130 if (fcb->gdal)
131 G_close_gdal_link(fcb->gdal);

http://grass.osgeo.org/programming6/closecell_8c_source.html#l00130

Thanks for your answer!

I found the problem: since I had a file the descriptor I closed it with the function close.
I didn't know that I need to call the function G_close_cell instead to deallocate the structures related to the file descriptor.

Thanks,
Matteo

matteo poletti wrote:

I found the problem: since I had a file the descriptor I closed it
with the function close.

I didn't know that I need to call the function G_close_cell instead
to deallocate the structures related to the file descriptor.

In GRASS 7, the value returned from the Rast_open_* functions (and
passed to other raster functions to identify a map) isn't a file
descriptor, but an index into a table of open maps.

In earlier versions, the value is both the descriptor of the open cell
file and an index into the table of open maps, so it's still necessary
to close maps with G_close_cell() or G_unopen_cell() in order to
release other resources associated with the map.

--
Glynn Clements <glynn@gclements.plus.com>