From 9c4ca0c5a64af81e2112c77ddbae45fb7b4cb77b Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 30 Jul 2024 19:19:46 +0200 Subject: [PATCH] core --- src/block.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/block.c b/src/block.c index b8d76c7..60c8d15 100644 --- a/src/block.c +++ b/src/block.c @@ -40,36 +40,23 @@ int add_new_block(chunk_t* chunk, size_t size, void *prev, bool is_used) void destroy_block(chunk_t *chunk) { - chunk_t chunk_prev, chunk_next, *first_chunk = chunk, *last_chunk = chunk; + chunk_t chunk_prev, chunk_next; if (chunk->prev != NULL) { chunk_read(chunk->prev, &chunk_prev); if (chunk_prev.block_id == chunk->block_id && chunk_prev.is_used == false) chunk_merge(&chunk_prev, chunk); - first_chunk = &chunk_prev; + chunk_prev.next = chunk->next; + chunk_write(&chunk_prev); } if (chunk->next != NULL) { chunk_read(chunk->next, &chunk_next); if (chunk_next.block_id == chunk->block_id && chunk_next.is_used == false) chunk_merge(chunk, &chunk_next); - last_chunk = &chunk_next; - } - - if (last_chunk != chunk) - { - last_chunk->prev = chunk->prev; - chunk_write(last_chunk); - } - - chunk->is_used = false; - chunk_write(chunk); - - if (first_chunk != chunk) - { - first_chunk->next = chunk->next; - chunk_write(first_chunk); + chunk_next.prev = chunk->prev; + chunk_write(&chunk_next); } munmap(chunk->current, get_physical_size(chunk));