shithub: scc

Download patch

ref: 7315d856a1485f20691652cc9b2e4165d8095cc4
parent: c79199da3e3565e28c2220a8474712a9fabc76e4
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Nov 21 12:53:40 EST 2021

libc: Merge&split correctly with next block

When the consecutive block is the next block we can merge it with
the block of realloc'ed pointer. In that case we have to remove
the next block from the free list, and insert the remaining part
of the merge in the list. To remove the next block we have to
modify the next pointer of the previous block and assign the next
block of the next pointer to the next pointer of the new block.

--- a/src/libc/stdlib/realloc.c
+++ b/src/libc/stdlib/realloc.c
@@ -50,7 +50,7 @@
 		if (avail > nunits) {
 			oh->h.size = nunits;
 			prev->h.next = new;
-			new->h.next = next;
+			new->h.next = next->h.next;
 			new->h.size = avail - nunits;
 			return oh + 1;
 		}