diff options
author | otto <> | 2006-05-14 19:53:40 +0000 |
---|---|---|
committer | otto <> | 2006-05-14 19:53:40 +0000 |
commit | f4c37a9f841e7402e56dcdfd8c296dfda1089c30 (patch) | |
tree | d353aef9cd6d37a1ddd372cb91bc80b240791e61 | |
parent | 9870da15fd30b13454e96db10a86d21087122b81 (diff) | |
download | openbsd-f4c37a9f841e7402e56dcdfd8c296dfda1089c30.tar.gz openbsd-f4c37a9f841e7402e56dcdfd8c296dfda1089c30.tar.bz2 openbsd-f4c37a9f841e7402e56dcdfd8c296dfda1089c30.zip |
Fix the second malloc_ulimit regression: maintaining the free list
requires memory; try to make sure we have it. If all fails, leak
instead of crash. Test case originally found by cloder@, fix tested
by many.
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index b858bbb739..028eff2b2d 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.82 2006/04/24 19:23:42 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.83 2006/05/14 19:53:40 otto Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * ---------------------------------------------------------------------------- | 4 | * ---------------------------------------------------------------------------- |
@@ -1158,6 +1158,10 @@ imalloc(size_t size) | |||
1158 | if (suicide) | 1158 | if (suicide) |
1159 | abort(); | 1159 | abort(); |
1160 | 1160 | ||
1161 | /* does not matter if malloc_bytes fails */ | ||
1162 | if (px == NULL) | ||
1163 | px = malloc_bytes(sizeof *px); | ||
1164 | |||
1161 | if (malloc_ptrguard && size == PTR_SIZE) { | 1165 | if (malloc_ptrguard && size == PTR_SIZE) { |
1162 | ptralloc = 1; | 1166 | ptralloc = 1; |
1163 | size = malloc_pagesize; | 1167 | size = malloc_pagesize; |
@@ -1405,8 +1409,8 @@ free_pages(void *ptr, u_long index, struct pginfo * info) | |||
1405 | mprotect(ptr, l, PROT_NONE); | 1409 | mprotect(ptr, l, PROT_NONE); |
1406 | 1410 | ||
1407 | /* Add to free-list. */ | 1411 | /* Add to free-list. */ |
1408 | if (px == NULL) | 1412 | if (px == NULL && (px = malloc_bytes(sizeof *px)) == NULL) |
1409 | px = imalloc(sizeof *px); /* This cannot fail... */ | 1413 | goto not_return; |
1410 | px->page = ptr; | 1414 | px->page = ptr; |
1411 | px->pdir = spi; | 1415 | px->pdir = spi; |
1412 | px->size = l; | 1416 | px->size = l; |
@@ -1766,6 +1770,11 @@ ifree(void *ptr) | |||
1766 | free_pages(ptr, index, info); | 1770 | free_pages(ptr, index, info); |
1767 | else | 1771 | else |
1768 | free_bytes(ptr, index, info); | 1772 | free_bytes(ptr, index, info); |
1773 | |||
1774 | /* does not matter if malloc_bytes fails */ | ||
1775 | if (px == NULL) | ||
1776 | px = malloc_bytes(sizeof *px); | ||
1777 | |||
1769 | return; | 1778 | return; |
1770 | } | 1779 | } |
1771 | 1780 | ||