summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/malloc.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2017-05-13 07:11:30 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2017-05-13 07:11:30 +0000
commitf5c17570b85b70d64eddeaf1d44fa6fbc2f76dd4 (patch)
tree9fa266885dd5338a99f6957f2ba89134041bba4a /lib/libc/stdlib/malloc.c
parent21e1dbcbeadd6c30bdf33e600fbdf7a0770fd8c8 (diff)
- fix bug wrt posix_memalign(3) of blocks between half a page and a page
- document posix_memalign() does not play nice with reacallocarray(3) and freezero(3)
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r--lib/libc/stdlib/malloc.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index dc395c4736c..999da6c1e9c 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: malloc.c,v 1.224 2017/04/22 09:12:49 otto Exp $ */
+/* $OpenBSD: malloc.c,v 1.225 2017/05/13 07:11:29 otto Exp $ */
/*
* Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
* Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -1974,15 +1974,20 @@ mapalign(struct dir_info *d, size_t alignment, size_t sz, int zero_fill)
}
static void *
-omemalign(struct dir_info *pool, size_t alignment, size_t sz, int zero_fill, void *f)
+omemalign(struct dir_info *pool, size_t alignment, size_t sz, int zero_fill,
+ void *f)
{
size_t psz;
void *p;
+ /* If between half a page and a page, avoid MALLOC_MOVE. */
+ if (sz > MALLOC_MAXCHUNK && sz < MALLOC_PAGESIZE)
+ sz = MALLOC_PAGESIZE;
if (alignment <= MALLOC_PAGESIZE) {
/*
- * max(size, alignment) is enough to assure the requested alignment,
- * since the allocator always allocates power-of-two blocks.
+ * max(size, alignment) is enough to assure the requested
+ * alignment, since the allocator always allocates
+ * power-of-two blocks.
*/
if (sz < alignment)
sz = alignment;