diff options
author | otto <> | 2017-05-13 07:11:29 +0000 |
---|---|---|
committer | otto <> | 2017-05-13 07:11:29 +0000 |
commit | 6d776cf3b18c53bba29005b258f7ac84cfd9d4b7 (patch) | |
tree | 041d1b78ebd7e83981f5e2f6d252cbfec020f873 /src/lib/libc/stdlib/malloc.c | |
parent | 88061d18303a68fc57c9f7abe5775cb7b6ba02c8 (diff) | |
download | openbsd-6d776cf3b18c53bba29005b258f7ac84cfd9d4b7.tar.gz openbsd-6d776cf3b18c53bba29005b258f7ac84cfd9d4b7.tar.bz2 openbsd-6d776cf3b18c53bba29005b258f7ac84cfd9d4b7.zip |
- 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 'src/lib/libc/stdlib/malloc.c')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index dc395c4736..999da6c1e9 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.224 2017/04/22 09:12:49 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.225 2017/05/13 07:11:29 otto Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * 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) | |||
1974 | } | 1974 | } |
1975 | 1975 | ||
1976 | static void * | 1976 | static void * |
1977 | omemalign(struct dir_info *pool, size_t alignment, size_t sz, int zero_fill, void *f) | 1977 | omemalign(struct dir_info *pool, size_t alignment, size_t sz, int zero_fill, |
1978 | void *f) | ||
1978 | { | 1979 | { |
1979 | size_t psz; | 1980 | size_t psz; |
1980 | void *p; | 1981 | void *p; |
1981 | 1982 | ||
1983 | /* If between half a page and a page, avoid MALLOC_MOVE. */ | ||
1984 | if (sz > MALLOC_MAXCHUNK && sz < MALLOC_PAGESIZE) | ||
1985 | sz = MALLOC_PAGESIZE; | ||
1982 | if (alignment <= MALLOC_PAGESIZE) { | 1986 | if (alignment <= MALLOC_PAGESIZE) { |
1983 | /* | 1987 | /* |
1984 | * max(size, alignment) is enough to assure the requested alignment, | 1988 | * max(size, alignment) is enough to assure the requested |
1985 | * since the allocator always allocates power-of-two blocks. | 1989 | * alignment, since the allocator always allocates |
1990 | * power-of-two blocks. | ||
1986 | */ | 1991 | */ |
1987 | if (sz < alignment) | 1992 | if (sz < alignment) |
1988 | sz = alignment; | 1993 | sz = alignment; |