aboutsummaryrefslogtreecommitdiff
path: root/src/lib/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mem.c')
-rw-r--r--src/lib/mem.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/mem.c b/src/lib/mem.c
index d738305..2b495ef 100644
--- a/src/lib/mem.c
+++ b/src/lib/mem.c
@@ -73,6 +73,7 @@ void* malloca(unsigned char size, unsigned char amnt)
unsigned long diff = (unsigned long)mem + i + 2;
diff %= amnt;
diff = amnt - diff;
+ diff %= amnt;
if((mem[i] == size) && mem[i+1]==0) {
if(diff == 0) {
mem[i] = size;
@@ -90,7 +91,6 @@ void* malloca(unsigned char size, unsigned char amnt)
diff += amnt;
}
mem[i] = diff-2;
- mem[i+1] = 0;
i += diff;
mem[i] = size;
mem[i+1] = 1;
@@ -116,6 +116,11 @@ void free(void* memloc)
for(unsigned int i = 0; i < size; i++) {
base[i+2] = 0;
}
+ // If it is the last entry, clear it and move the heap top down
+ if (base + size + 2 == rpi_heap_top) {
+ base[0] = 0;
+ rpi_heap_top = base;
+ }
}
void* heap_base(void)