On Tue, May 07, 2013 at 12:43:48AM -0400, Ted Unangst wrote:
> If growing the current region fails, realloc will leave errno set,
> even though the function will eventually succeed.
(Late reply because I was away on vacation)
I don't think this is correct. realloc itself already takes care of this.
-Otto
>
> Index: stdlib/malloc.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/stdlib/malloc.c,v
> retrieving revision 1.149
> diff -u -p -r1.149 malloc.c
> --- stdlib/malloc.c 22 Dec 2012 07:32:17 -0000 1.149
> +++ stdlib/malloc.c 7 May 2013 04:41:45 -0000
> @@ -1297,6 +1297,7 @@ orealloc(void *p, size_t newsz, void *f)
> if (!mopts.malloc_guard) {
> void *hint = (char *)p + roldsz;
> size_t needed = rnewsz - roldsz;
> + int saved_errno = errno;
>
> STATS_INC(g_pool->cheap_realloc_tries);
> zapcacheregion(g_pool, hint, needed);
> @@ -1317,6 +1318,7 @@ orealloc(void *p, size_t newsz, void *f)
> if (munmap(q, needed))
> wrterror("munmap", q);
> }
> + errno = saved_errno;
> }
> } else if (rnewsz < roldsz) {
> if (mopts.malloc_guard) {