On Tue, May 10, 2016 at 02:48:18PM -0400, Daniel Micay wrote: > The ENOMEM errno wasn't being set in some code paths where it was gated > behind mopts.malloc_xmalloc:
Called functions do set errno..., you're effectively overriding those. Which means those can go if this is applied. This needs more work/thought (and is gong to conflict with my milt-pool diff). -Otto > > diff --git a/stdlib/malloc.c b/stdlib/malloc.c > index bc328d2..aa6f0a3 100644 > --- a/stdlib/malloc.c > +++ b/stdlib/malloc.c > @@ -1224,8 +1224,9 @@ malloc(size_t size) > r = omalloc(d, size, 0, CALLER); > d->active--; > _MALLOC_UNLOCK(); > - if (r == NULL && mopts.malloc_xmalloc) { > - wrterror(d, "out of memory", NULL); > + if (r == NULL) { > + if (mopts.malloc_xmalloc) > + wrterror(d, "out of memory", NULL); > errno = ENOMEM; > } > if (r != NULL) > @@ -1510,8 +1511,9 @@ realloc(void *ptr, size_t size) > > d->active--; > _MALLOC_UNLOCK(); > - if (r == NULL && mopts.malloc_xmalloc) { > - wrterror(d, "out of memory", NULL); > + if (r == NULL) { > + if (mopts.malloc_xmalloc) > + wrterror(d, "out of memory", NULL); > errno = ENOMEM; > } > if (r != NULL) > @@ -1563,8 +1565,9 @@ calloc(size_t nmemb, size_t size) > > d->active--; > _MALLOC_UNLOCK(); > - if (r == NULL && mopts.malloc_xmalloc) { > - wrterror(d, "out of memory", NULL); > + if (r == NULL) { > + if (mopts.malloc_xmalloc) > + wrterror(d, "out of memory", NULL); > errno = ENOMEM; > } > if (r != NULL) > @@ -1694,10 +1697,9 @@ posix_memalign(void **memptr, size_t alignment, size_t > size) > d->active--; > _MALLOC_UNLOCK(); > if (r == NULL) { > - if (mopts.malloc_xmalloc) { > + if (mopts.malloc_xmalloc) > wrterror(d, "out of memory", NULL); > - errno = ENOMEM; > - } > + errno = ENOMEM; > goto err; > } > errno = saved_errno; > -- > 2.8.2