| ... | @@ -379,8 +379,11 @@ const WasmPageAllocator = struct { | ... | @@ -379,8 +379,11 @@ const WasmPageAllocator = struct { |
| 379 | } | 379 | } |
| 380 | | 380 | |
| 381 | if (free_start < extendedOffset()) { | 381 | if (free_start < extendedOffset()) { |
| 382 | conventional.recycle(free_start, free_end - free_start); | 382 | const clamped_end = std.math.min(extendedOffset(), free_end); |
| 383 | } else { | 383 | conventional.recycle(free_start, clamped_end - free_start); |
| | 384 | } |
| | 385 | |
| | 386 | if (free_end > extendedOffset()) { |
| 384 | if (extended.totalPages() == 0) { | 387 | if (extended.totalPages() == 0) { |
| 385 | // Steal the last page from the memory currently being recycled | 388 | // Steal the last page from the memory currently being recycled |
| 386 | // TODO: would it be better if we use the first page instead? | 389 | // TODO: would it be better if we use the first page instead? |
| ... | @@ -390,7 +393,8 @@ const WasmPageAllocator = struct { | ... | @@ -390,7 +393,8 @@ const WasmPageAllocator = struct { |
| 390 | // Since this is the first page being freed and we consume it, assume *nothing* is free. | 393 | // Since this is the first page being freed and we consume it, assume *nothing* is free. |
| 391 | std.mem.set(u8, extended.bytes, FreeBlock.used); | 394 | std.mem.set(u8, extended.bytes, FreeBlock.used); |
| 392 | } | 395 | } |
| 393 | extended.recycle(free_start - extendedOffset(), free_end - free_start); | 396 | const clamped_start = std.math.max(extendedOffset(), free_start); |
| | 397 | extended.recycle(clamped_start - extendedOffset(), free_end - clamped_start); |
| 394 | } | 398 | } |
| 395 | } | 399 | } |
| 396 | | 400 | |