diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 17 |
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) |
11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.52 2002/11/25 00:06:51 cloder Exp $"; | 11 | static 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) |