Pádraig Brady wrote: > ... then we need to use realloc like this I think: > > errno=0 > np = realloc (p, n); > if (np==NULL && errno==ENOMEM) { > free (p); > error (); > } > > I.E. xrealloc etc. should be changed to check ENOMEM as above?
This way of checking realloc's return value is a correct one. But the one we have in lib/xmalloc.c currently is correct as well. The difference between the two is when p == NULL && n == 0 on glibc systems. In this case, - your proposed code realizes that glibc was out of memory and fails, - the current code returns NULL, like it would do on AIX and OSF/1 systems. Since xrealloc does not guarantee that xrealloc(NULL,0) != NULL, failing in this situation on glibc is unnecessary. Bruno