[GRASS5] Re: r.sun improvements

Glynn Clements glynn.clements at virgin.net
Thu Apr 10 12:05:41 EDT 2003


H Bowman wrote:

> while we're at it, s.out.ascii's memory use is pretty terrible, and
> grows out of control as well. The program is only a few lines long, so
> maybe someone who knows the libraries better than I could spot it.

    while (G_site_get (fd, site) == 0)
    {
	...
	    if (!full)
	...
            else
	      fprintf (stdout,"%s\n", G_site_format (site, fs, strip));
    }

G_site_format() uses malloc() to allocate the buffer for the returned
string, so it needs to be free()d afterwards.

-------------- next part --------------
--- src/sites/s.out.ascii/main.c~	Fri Jan 12 08:16:49 2001
+++ src/sites/s.out.ascii/main.c	Thu Apr 10 17:04:25 2003
@@ -114,7 +114,11 @@
               fprintf (stdout,"\n");
             }
             else
-	      fprintf (stdout,"%s\n", G_site_format (site, fs, strip));
+	    {
+	      char *str = G_site_format (site, fs, strip);
+	      fprintf (stdout,"%s\n", str);
+	      G_free(str);
+	    }
 	}
     }
     fclose (fd);


More information about the grass-dev mailing list