Did not realise that it was implementation-specific. Never mind then, I will call free explicitly.
On Thu, 17 Mar 2016 09:58:31 +0000 Dimitris Papastamos <[email protected]> wrote: > On Thu, Mar 17, 2016 at 10:11:02AM +0100, Mattias Andrée > wrote: > > Signed-off-by: Mattias Andrée <[email protected]> > > --- > > libutil/ealloc.c | 2 +- > > libutil/reallocarray.c | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/libutil/ealloc.c b/libutil/ealloc.c > > index 320865d..5a3cce1 100644 > > --- a/libutil/ealloc.c > > +++ b/libutil/ealloc.c > > @@ -60,7 +60,7 @@ void * > > enrealloc(int status, void *p, size_t size) > > { > > p = realloc(p, size); > > - if (!p) > > + if (!p && size) > > enprintf(status, "realloc: out of > > memory\n"); return p; > > } > > diff --git a/libutil/reallocarray.c > > b/libutil/reallocarray.c index c6e5219..b964626 100644 > > --- a/libutil/reallocarray.c > > +++ b/libutil/reallocarray.c > > @@ -43,7 +43,7 @@ ereallocarray(void *optr, size_t > > nmemb, size_t size) { > > void *p; > > > > - if (!(p = reallocarray(optr, nmemb, size))) > > + if (!(p = reallocarray(optr, nmemb, size)) && > > nmemb && size) eprintf("reallocarray: out of memory\n"); > > > > return p; > > This is implementation-defined behaviour, exiting is also > valid. Don't write code that relies on this idiom. > > I am aware we have not documented this behaviour but > that's minor in my opinion. >
pgpPZewkAf07p.pgp
Description: OpenPGP digital signature
