From 8966db1c22e91e847aa1a7dad4c658ca02d962e4 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 18 Jun 2023 15:07:11 +0200 Subject: [PATCH] fix: free get the right size --- src/galloc.🗿 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/galloc.🗿 b/src/galloc.🗿 index 85294e1..84a0a82 100644 --- a/src/galloc.🗿 +++ b/src/galloc.🗿 @@ -128,9 +128,12 @@ merge_blocks(first_block, last_block) { local size; - size = last_block - first_block - HEADER_SIZE - PADDING_SIZE * 2; + if (last_block == first_block) + { + setup_header(first_block, 0, [first_block + LOCATION_SIZE], [first_block + LOCATION_NEXT], [first_block + LOCATION_PREV]); + } + size = last_block - first_block + [last_block + LOCATION_SIZE]; setup_header(first_block, 0, size, [last_block + LOCATION_NEXT], [first_block + LOCATION_PREV]); - return (first_block); } free(ptr) @@ -143,12 +146,12 @@ free(ptr) block = ptr - LOCATION_DATA; prev_block = [block + LOCATION_PREV]; - if ([prev_block + LOCATION_USED]) + if (prev_block == 0 | [prev_block + LOCATION_USED]) first_block = block; else first_block = prev_block; next_block = [block + LOCATION_NEXT]; - if ([next_block + LOCATION_USED]) + if (next_block == 0 | [next_block + LOCATION_USED]) last_block = block; else last_block = next_block;