[GRASS5] Strange exit() (xganim)

Glynn Clements glynn at gclements.plus.com
Tue Jul 26 04:10:58 EDT 2005


Brad Douglas wrote:

> Is there any particular reason for exit(0)?  Shouldn't it be exit(1)?
> 
> if(NULL == (tr = malloc(tsiz * sizeof(char)))){
>     fprintf(stderr,"Unable to malloc.\n");
>     exit (0);
> }

Yes.

> Ideally, shouldn't this just be:
> 
> if (NULL == (tr = G_malloc(tsiz * sizeof(char))))
>     G_fatal_error(_("Unable to allocate memory."));
> 

Actually, it should just be:

	tr = G_malloc(tsiz * sizeof(char));

G_malloc() calls G_fatal_error() itself if malloc() fails:

	void *G_malloc (size_t n)
	{
	    void *buf;
	
	    if (n <= 0) n = 1;	/* make sure we get a valid request */
	
	    buf = malloc(n);
	    if(buf) return buf;
	
	    G_fatal_error ("G_malloc: out of memory");
	    return NULL;
	}

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




More information about the grass-dev mailing list