summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2008-08-25 17:56:18 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2008-08-25 17:56:18 +0000
commitd6b739b4f65515fd25b058bfdddfc22657493aba (patch)
tree54f166c22053daf2d637abcb202d352363045c69 /lib/libc
parent1b5691bd4b6751621294a6faabfb13b4974ce949 (diff)
Make all combinations of G, P, J and zero-fill work with as little
effort as possible in most cases; ok djm@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdlib/malloc.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 1cbe7fa0842..be80640e813 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: malloc.c,v 1.97 2008/08/23 07:49:38 djm Exp $ */
+/* $OpenBSD: malloc.c,v 1.98 2008/08/25 17:56:17 otto Exp $ */
/*
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
*
@@ -1078,8 +1078,6 @@ omalloc(size_t sz, int zero_fill)
errno = ENOMEM;
return NULL;
}
- if (malloc_junk)
- memset(p + sz, SOME_JUNK, psz - sz);
if (malloc_guard) {
if (mprotect((char *)p + psz - malloc_guard,
malloc_guard, PROT_NONE))
@@ -1087,11 +1085,28 @@ omalloc(size_t sz, int zero_fill)
malloc_guarded += malloc_guard;
}
- /* shift towards the end */
if (malloc_move &&
- sz - malloc_guard < MALLOC_PAGESIZE - MALLOC_MINSIZE)
+ sz - malloc_guard < MALLOC_PAGESIZE - MALLOC_MINSIZE) {
+ /* fill whole allocation */
+ if (malloc_junk)
+ memset(p, SOME_JUNK, psz - malloc_guard);
+ /* shift towards the end */
p = ((char *)p) + ((MALLOC_PAGESIZE - MALLOC_MINSIZE -
(sz - malloc_guard)) & ~(MALLOC_MINSIZE-1));
+ /* fill zeros if needed and overwritten above */
+ if (zero_fill && malloc_junk)
+ memset(p, 0, sz - malloc_guard);
+ } else {
+ if (malloc_junk) {
+ if (zero_fill)
+ memset(p + sz - malloc_guard,
+ SOME_JUNK, psz - sz);
+ else
+ memset(p,
+ SOME_JUNK, psz - malloc_guard);
+ }
+ }
+
} else {
/* takes care of SOME_JUNK */
p = malloc_bytes(&g_pool, sz);