Remove block header from allocated blocks entirely

This commit is contained in:
Imbus 2025-09-08 07:52:41 +02:00
parent 8f41b0873d
commit 13a0d42514

View file

@ -4,10 +4,11 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Initialize the FreeList */
int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize) {
size_t size = ALIGN(itemsize + sizeof(FreeListBlock));
size_t size = ALIGN(itemsize);
if (!fl || end <= start)
return EXIT_FAILURE;
@ -39,7 +40,8 @@ void *fl_alloc(FreeList *fl) {
fl->free = fl->free->next;
fl->allocated++;
return ((void *)m) + sizeof(FreeListBlock);
memset((void *)m, 0, sizeof(FreeListBlock));
return ((void *)m);
}
/* Return some memory to the FreeList */
@ -48,7 +50,7 @@ int fl_free(FreeList *fl, void *ptr) {
return EXIT_FAILURE; /* We cant free memory we do not own */
}
FreeListBlock *block = (FreeListBlock *)((uintptr_t)ptr - sizeof(FreeListBlock));
FreeListBlock *block = (FreeListBlock *)(uintptr_t)ptr;
block->next = fl->free;
fl->free = block;