[GRASS5] Re: [GRASSLIST:2288] Re: s.sample gets killed

Glynn Clements glynn.clements at virgin.net
Tue Jan 20 01:46:04 EST 2004

Hamish wrote:

> > I need to extract raster cell values for a large number (approx. 2.5
> > million) of sites. Unfortunately s.sample gets killed after probing a
> > few thousand sites without apparent reason. No error message is given,
> > just 'killed'. Has anybody encountered the same problem and found a
> > solution or workaround?
> Sounds like you are running out of memory.
> can you run "top" to watch the memory use while s.sample runs?
> hit "M" while top is running to sort processes by memory use.
> Maybe it is a memory leak -- does the memory use steadily grow as the
> program runs or is it all allocated at once? How big does it get? Please
> post results so we can fix it if need be.

It's almost certainly due to a memory leak in libgis.

s.sample calls G_readsites_xyz() in a loop; G_readsites_xyz() calls
G_site_new_struct() to allocate a Site structure and
G_site_free_struct() to free it.

G_site_new_struct() allocates the dim, str_att and dbl_att arrays, and
also allocates a buffer for each entry in the str_att array. 
G_site_free_struct() frees these arrays, but *doesn't* free the
buffers in the str_att array.

The attached patch fixes that; however, it should probably be tested
before being commited. AFAICT, the following programs may be affected:

d.extend d.pan d.site.labels d.site.pg d.sites d.sites.qual
d.vect.labels d.what.sites d.zoom g.region m.in.e00 p.map p.map.new
ps.map r.cost r.random r.to.sites r.volume s.delaunay s.hull
s.in.ascii s.in.dbf s.info s.in.shape s.mask s.out.ascii s.out.e00
s.perturb s.proj s.qcount s.random s.sample s.surf.idw s.surf.rst
s.territory s.to.rast s.to.vect s.vol.rst s.voronoi s.what s.windavg
v.circle v.in.tig.lndmk v.surf.rst v.to.sites v.out.moss NVIZ

Glynn Clements <glynn.clements at virgin.net>

-------------- next part --------------
--- src/libes/gis/sites.c~	Thu Sep  4 22:59:41 2003
+++ src/libes/gis/sites.c	Tue Jan 20 06:40:38 2004
@@ -241,7 +241,12 @@
+  {
+      int i;
+      for (i = 0; i < s->str_alloc; i++)
+          G_free(s->str_att[i]);
+  }

More information about the grass-dev mailing list