core: simplify bozo code

This commit is contained in:
starnakin 2024-07-31 14:42:19 +02:00
parent 253d037344
commit c7e205c8e5

View File

@ -47,36 +47,28 @@ static void (*free_funcs[3])(chunk_t*) = {free_tiny, free_small, free_large};
void ft_free(void *ptr)
{
void **root;
void *raw_chunk;
chunk_t chunk;
size_t i;
if (ptr == NULL)
return;
for (i = TINY; i <= LARGE + 1; i++)
for (i = TINY; i <= LARGE; i++)
{
#ifdef DEBUG
if (i > LARGE)
write(2, "chunk not found\n", 16);
#endif
root = allocs_tree[i];
raw_chunk = raw_get_chunk(root, ptr);
raw_chunk = raw_get_chunk(allocs_tree[i], ptr);
if (raw_chunk == NULL)
continue;
break;
}
#ifdef DEBUG
if (raw_chunk == NULL)
write(2, "chunk not found\n", 16);
#endif
chunk_read(raw_chunk, &chunk);
#ifdef DEBUG
if (chunk.is_used == false)
write(2, "double free\n", 12);
#endif
// CALL THE RIGHT FREE FUNCTION DEPEND ON SIZE
free_funcs[i](&chunk);
}