Skip to content

Commit 4466451

Browse files
committed
Fix realloc shrink adjacency check
The merge check compared block + size instead of block + old_size, making it dead code. Leftover fragments were never merged with adjacent free blocks. Signed-off-by: Nicolas 'Pixel' Noble <nicolas@nobis-crew.org>
1 parent c2ad3b2 commit 4466451

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/mips/psyqo/src/alloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ void *psyqo_realloc(void *ptr_, size_t size_) {
584584
if (size < old_size) {
585585
// We're going to create a new block at the end of what we are re-allocating.
586586
empty_block *new_block = (empty_block *)((char *)block + size);
587-
// Is the next block adjacent to the block we're re-allocating?
588-
if ((next != &marker) && (((char *)block + size) == (char *)next)) {
587+
// Is the next block adjacent to the end of our original allocation?
588+
if ((next != &marker) && (((char *)block + old_size) == (char *)next)) {
589589
// Yes, we can merge them.
590590
new_block->next = next->next;
591591
new_block->size = old_size - size + next->size;

0 commit comments

Comments
 (0)