From: David van Moolenbroek Date: Wed, 28 Oct 2015 01:05:39 +0000 (+0000) Subject: libc: fix needless malloc failures X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F3217%2F2;p=minix.git libc: fix needless malloc failures The NetBSD libc malloc implementation performs its own out-of-memory check, presumably for performance reasons. The check makes a strong assumption about the address space layout, which is that memory- mapped pages are always located above the heap. However, this assumption does not necessarily hold on MINIX3, thus resulting in malloc reporting an out-of-memory condition without the system actually being out of memory at all. Evidence suggests that in particular dynamically linked (i.e., pkgsrc) binaries were affected by this issue - most notably git. Change-Id: If542fbace0a1cce12aa9e075d51992cbbbf26e94 --- diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 5d35e4b41..0570244ed 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -818,8 +818,10 @@ imalloc(size_t size) if ((size + malloc_pagesize) < size) /* Check for overflow */ result = NULL; +#ifndef __minix else if ((size + malloc_pagesize) >= (uintptr_t)page_dir) result = NULL; +#endif /* !__minix */ else if (size <= malloc_maxsize) result = malloc_bytes(size); else