From 2a55c1e7762b910f169a34db76f9a71719ba34fd Mon Sep 17 00:00:00 2001 From: tdeval <> Date: Wed, 27 Nov 2002 21:40:32 +0000 Subject: [PATCH] Honour malloc_junk ('J') with realloc(3), and fix page_dir shrink update. --- src/lib/libc/stdlib/malloc.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 45a8cc81..9ab3deb5 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/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)