From c7e205c8e504f8256b4e12b7aec45ed378c20077 Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 31 Jul 2024 14:42:19 +0200 Subject: [PATCH] core: simplify bozo code --- src/free.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/free.c b/src/free.c index 472a4ff..de65484 100644 --- a/src/free.c +++ b/src/free.c @@ -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); } \ No newline at end of file