summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorThierry Deval <tdeval@cvs.openbsd.org>2002-11-27 21:40:33 +0000
committerThierry Deval <tdeval@cvs.openbsd.org>2002-11-27 21:40:33 +0000
commitd89097e161bdceaa7d8366237301a50ee9b885b4 (patch)
tree177171b6f257db8b8a7e8a94b7e5519274248dc0 /lib/libc/stdlib
parent5c3f7bfe5c5822d32088033116f9da5b080cb384 (diff)
Honour malloc_junk ('J') with realloc(3), and fix page_dir shrink update.
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/malloc.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 45a8cc8182e..9ab3deb5dfe 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -8,7 +8,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: malloc.c,v 1.52 2002/11/25 00:06:51 cloder Exp $";
+static char rcsid[] = "$OpenBSD: malloc.c,v 1.53 2002/11/27 21:40:32 tdeval Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -893,10 +893,12 @@ irealloc(ptr, size)
for (osize = malloc_pagesize; *++mp == MALLOC_FOLLOW;)
osize += malloc_pagesize;
- if (!malloc_realloc && /* unless we have to, */
+ if (!malloc_realloc && /* Unless we have to, */
size <= osize && /* .. or are too small, */
size > (osize - malloc_pagesize)) { /* .. or can free a page, */
- return ptr; /* don't do anything. */
+ if (malloc_junk)
+ memset((char *)ptr + size, SOME_JUNK, osize-size);
+ return ptr; /* ..don't do anything else. */
}
} else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */
@@ -919,10 +921,12 @@ irealloc(ptr, size)
osize = (*mp)->size;
if (!malloc_realloc && /* Unless we have to, */
- size < osize && /* ..or are too small, */
+ size <= osize && /* ..or are too small, */
(size > osize/2 || /* ..or could use a smaller size, */
osize == malloc_minsize)) { /* ..(if there is one) */
- return ptr; /* ..Don't do anything */
+ if (malloc_junk)
+ memset((char *)ptr + size, SOME_JUNK, osize-size);
+ return ptr; /* ..don't do anything else. */
}
} else {
@@ -1070,11 +1074,12 @@ free_pages(ptr, index, info)
malloc_brk = pf->end;
index = ptr2index(pf->end);
- last_index = index - 1;
for(i=index;i <= last_index;)
page_dir[i++] = MALLOC_NOT_MINE;
+ last_index = index - 1;
+
/* XXX: We could realloc/shrink the pagedir here I guess. */
}
if (pt)