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