[coreboot] r3510 - trunk/payloads/libpayload/libc

svn at coreboot.org svn at coreboot.org
Thu Aug 14 16:40:10 CEST 2008


Author: stepan
Date: 2008-08-14 16:40:10 +0200 (Thu, 14 Aug 2008)
New Revision: 3510

Modified:
   trunk/payloads/libpayload/libc/malloc.c
Log:
* 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 at coresystems.de>
Acked-by: Jordan Crouse <jordan.crouse at amd.com>



Modified: trunk/payloads/libpayload/libc/malloc.c
===================================================================
--- trunk/payloads/libpayload/libc/malloc.c	2008-08-13 12:16:15 UTC (rev 3509)
+++ trunk/payloads/libpayload/libc/malloc.c	2008-08-14 14:40:10 UTC (rev 3510)
@@ -92,13 +92,15 @@
 		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 @@
 
 				if (nsize > 0)
 					*((hdrtype_t *) nptr) =
-					    FREE_BLOCK(nsize - 4);
+					    FREE_BLOCK(nsize);
 
 				return (void *)(ptr + HDRSIZE);
 			}





More information about the coreboot mailing list