This commit is contained in:
starnakin 2024-07-30 19:19:46 +02:00
parent 545c02c8f8
commit 9c4ca0c5a6

View File

@ -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) 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) if (chunk->prev != NULL)
{ {
chunk_read(chunk->prev, &chunk_prev); chunk_read(chunk->prev, &chunk_prev);
if (chunk_prev.block_id == chunk->block_id && chunk_prev.is_used == false) if (chunk_prev.block_id == chunk->block_id && chunk_prev.is_used == false)
chunk_merge(&chunk_prev, chunk); chunk_merge(&chunk_prev, chunk);
first_chunk = &chunk_prev; chunk_prev.next = chunk->next;
chunk_write(&chunk_prev);
} }
if (chunk->next != NULL) if (chunk->next != NULL)
{ {
chunk_read(chunk->next, &chunk_next); chunk_read(chunk->next, &chunk_next);
if (chunk_next.block_id == chunk->block_id && chunk_next.is_used == false) if (chunk_next.block_id == chunk->block_id && chunk_next.is_used == false)
chunk_merge(chunk, &chunk_next); chunk_merge(chunk, &chunk_next);
last_chunk = &chunk_next; chunk_next.prev = chunk->prev;
} chunk_write(&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);
} }
munmap(chunk->current, get_physical_size(chunk)); munmap(chunk->current, get_physical_size(chunk));