aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}