Remove tracking of free state in freelist header since being in the list means it is also free

This commit is contained in:
Imbus 2025-09-08 07:38:22 +02:00
parent 69d4683cc5
commit 39c331cd09
3 changed files with 1 additions and 11 deletions

View file

@ -33,7 +33,6 @@ int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize) {
FreeListBlock *block = (FreeListBlock *)start;
for (size_t i = 0; i < fl_capacity(fl); i++) {
block->next = (FreeListBlock *)((void *)block + size);
block->block_state = FL_FREE;
block = block->next;
}
@ -45,11 +44,10 @@ int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize) {
/* Allocate some memory from the FreeList */
void *fl_alloc(FreeList *fl) {
if (!fl->free || fl->free->block_state != FL_FREE)
if (!fl->free)
return NULL;
FreeListBlock *m = fl->free;
m->block_state = FL_USED;
fl->free = fl->free->next;
fl->allocated++;
@ -65,11 +63,6 @@ int fl_free(FreeList *fl, void *ptr) {
FreeListBlock *block = (FreeListBlock *)((uintptr_t)ptr - sizeof(FreeListBlock));
if (block->block_state != FL_USED) {
return EXIT_FAILURE; /* Block must be used */
}
block->block_state = FL_FREE;
block->next = fl->free;
fl->free = block;
fl->allocated--;
@ -109,7 +102,6 @@ size_t fl_check(FreeList *fl) {
while (cursor->next != NULL) {
avail++;
assert(cursor->block_state == FL_FREE);
cursor = cursor->next;
}