summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdeval <>2002-11-27 21:40:32 +0000
committertdeval <>2002-11-27 21:40:32 +0000
commit67603614edacd4bbbfcbe86a0c4e6f2b0c731c09 (patch)
treec35177fb41330bfca1f90337d4a79d646b58038d
parent6099547bdd329566c7d0de2622581e5ab234b47b (diff)
downloadopenbsd-67603614edacd4bbbfcbe86a0c4e6f2b0c731c09.tar.gz
openbsd-67603614edacd4bbbfcbe86a0c4e6f2b0c731c09.tar.bz2
openbsd-67603614edacd4bbbfcbe86a0c4e6f2b0c731c09.zip
Honour malloc_junk ('J') with realloc(3), and fix page_dir shrink update.
-rw-r--r--src/lib/libc/stdlib/malloc.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index 45a8cc8182..9ab3deb5df 100644
--- a/src/lib/libc/stdlib/malloc.c
+++ b/src/lib/libc/stdlib/malloc.c
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10#if defined(LIBC_SCCS) && !defined(lint) 10#if defined(LIBC_SCCS) && !defined(lint)
11static char rcsid[] = "$OpenBSD: malloc.c,v 1.52 2002/11/25 00:06:51 cloder Exp $"; 11static char rcsid[] = "$OpenBSD: malloc.c,v 1.53 2002/11/27 21:40:32 tdeval Exp $";
12#endif /* LIBC_SCCS and not lint */ 12#endif /* LIBC_SCCS and not lint */
13 13
14/* 14/*
@@ -893,10 +893,12 @@ irealloc(ptr, size)
893 for (osize = malloc_pagesize; *++mp == MALLOC_FOLLOW;) 893 for (osize = malloc_pagesize; *++mp == MALLOC_FOLLOW;)
894 osize += malloc_pagesize; 894 osize += malloc_pagesize;
895 895
896 if (!malloc_realloc && /* unless we have to, */ 896 if (!malloc_realloc && /* Unless we have to, */
897 size <= osize && /* .. or are too small, */ 897 size <= osize && /* .. or are too small, */
898 size > (osize - malloc_pagesize)) { /* .. or can free a page, */ 898 size > (osize - malloc_pagesize)) { /* .. or can free a page, */
899 return ptr; /* don't do anything. */ 899 if (malloc_junk)
900 memset((char *)ptr + size, SOME_JUNK, osize-size);
901 return ptr; /* ..don't do anything else. */
900 } 902 }
901 903
902 } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */ 904 } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */
@@ -919,10 +921,12 @@ irealloc(ptr, size)
919 osize = (*mp)->size; 921 osize = (*mp)->size;
920 922
921 if (!malloc_realloc && /* Unless we have to, */ 923 if (!malloc_realloc && /* Unless we have to, */
922 size < osize && /* ..or are too small, */ 924 size <= osize && /* ..or are too small, */
923 (size > osize/2 || /* ..or could use a smaller size, */ 925 (size > osize/2 || /* ..or could use a smaller size, */
924 osize == malloc_minsize)) { /* ..(if there is one) */ 926 osize == malloc_minsize)) { /* ..(if there is one) */
925 return ptr; /* ..Don't do anything */ 927 if (malloc_junk)
928 memset((char *)ptr + size, SOME_JUNK, osize-size);
929 return ptr; /* ..don't do anything else. */
926 } 930 }
927 931
928 } else { 932 } else {
@@ -1070,11 +1074,12 @@ free_pages(ptr, index, info)
1070 malloc_brk = pf->end; 1074 malloc_brk = pf->end;
1071 1075
1072 index = ptr2index(pf->end); 1076 index = ptr2index(pf->end);
1073 last_index = index - 1;
1074 1077
1075 for(i=index;i <= last_index;) 1078 for(i=index;i <= last_index;)
1076 page_dir[i++] = MALLOC_NOT_MINE; 1079 page_dir[i++] = MALLOC_NOT_MINE;
1077 1080
1081 last_index = index - 1;
1082
1078 /* XXX: We could realloc/shrink the pagedir here I guess. */ 1083 /* XXX: We could realloc/shrink the pagedir here I guess. */
1079 } 1084 }
1080 if (pt) 1085 if (pt)