summaryrefslogtreecommitdiff
path: root/payloads/libpayload
diff options
context:
space:
mode:
authorStefan Reinauer <stepan@coresystems.de>2008-08-14 14:40:10 +0000
committerStefan Reinauer <stepan@openbios.org>2008-08-14 14:40:10 +0000
commitee673194b45efda3e21507d57ef11ba190e9a502 (patch)
treef81e47224a9dec3a8bd72d36303d30bed73fd1b0 /payloads/libpayload
parent8e65adb67d9d85e920554af7b083b3d76b885688 (diff)
downloadcoreboot-ee673194b45efda3e21507d57ef11ba190e9a502.tar.xz
* fix memory allocator bug that lead to freelist corruption on the first malloc
(and spent 8 bytes too much per malloc) * if the memory allocator detects freelist corruption, print a message instead of silently dying. Signed-off-by: Stefan Reinauer <stepan@coresystems.de> Acked-by: Jordan Crouse <jordan.crouse@amd.com> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3510 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload')
-rw-r--r--payloads/libpayload/libc/malloc.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c
index fe3d45bab8..3c6cf5d833 100644
--- a/payloads/libpayload/libc/malloc.c
+++ b/payloads/libpayload/libc/malloc.c
@@ -92,13 +92,15 @@ static void *alloc(int len)
header = *((hdrtype_t *) ptr);
int size = SIZE(header);
- if (!HAS_MAGIC(header) || size == 0)
+ if (!HAS_MAGIC(header) || size == 0) {
+ printf("memory allocator panic.\n");
halt();
+ }
if (header & FLAG_FREE) {
if (len <= size) {
void *nptr = ptr + (HDRSIZE + len);
- int nsize = size - (len + 8);
+ int nsize = size - (HDRSIZE + len);
/* Mark the block as used. */
*((hdrtype_t *) ptr) = USED_BLOCK(len);
@@ -109,7 +111,7 @@ static void *alloc(int len)
if (nsize > 0)
*((hdrtype_t *) nptr) =
- FREE_BLOCK(nsize - 4);
+ FREE_BLOCK(nsize);
return (void *)(ptr + HDRSIZE);
}