[GRASS5] Strange exit() (xganim)

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);
}

Ideally, shouldn't this just be:

if (NULL == (tr = G_malloc(tsiz * sizeof(char))))
    G_fatal_error(_("Unable to allocate memory."));

--
Brad Douglas <rez@touchofmadness.com>

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@gclements.plus.com>