From 07728cb10a617c0d298e81bc17c075cbde0ad906 Mon Sep 17 00:00:00 2001 From: lax1dude Date: Sat, 9 Nov 2024 17:58:19 -0800 Subject: [PATCH] Fix defragmentation --- core/src/main/java/org/teavm/runtime/LaxMalloc.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/teavm/runtime/LaxMalloc.java b/core/src/main/java/org/teavm/runtime/LaxMalloc.java index ebf329e03..483b5c512 100644 --- a/core/src/main/java/org/teavm/runtime/LaxMalloc.java +++ b/core/src/main/java/org/teavm/runtime/LaxMalloc.java @@ -335,7 +335,7 @@ public final class LaxMalloc { // set the chunk no longer in use chunkSize &= 0x7FFFFFFF; - if (addrHeap(ADDR_HEAP_DATA_START).isLessThan(chunkPtr)) { + if (!chunkPtr.isLessThan(addrHeap(ADDR_HEAP_DATA_START))) { // check if we can merge with the previous chunk, and move it to another bucket Address prevChunkPtr = chunkPtr.add(-(chunkPtr.add(-4).getInt())); int prevChunkSize = readChunkSizeStatus(prevChunkPtr); @@ -353,7 +353,7 @@ public final class LaxMalloc { } Address nextChunkPtr = chunkPtr.add(chunkSize); - if (addrHeap(ADDR_HEAP_INNER_LIMIT).getAddress().isLessThan(nextChunkPtr)) { + if (nextChunkPtr.isLessThan(addrHeap(ADDR_HEAP_INNER_LIMIT).getAddress())) { // check if we can merge with the next chunk as well int nextChunkSize = readChunkSizeStatus(nextChunkPtr); if ((nextChunkSize & 0x80000000) == 0) {