From fdfaaa8cec75c240c41f83817a58521b59591523 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 12 Sep 2024 16:05:31 +0100 Subject: [PATCH] Fix memory allocator issue. Windows and unix allocators would panic when asked to allocate the maximum size. --- internal/alloc/alloc_unix.go | 2 +- internal/alloc/alloc_windows.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/alloc/alloc_unix.go b/internal/alloc/alloc_unix.go index 39a3a38..009cc1f 100644 --- a/internal/alloc/alloc_unix.go +++ b/internal/alloc/alloc_unix.go @@ -39,7 +39,7 @@ type mmappedMemory struct { func (m *mmappedMemory) Reallocate(size uint64) []byte { com := uint64(len(m.buf)) res := uint64(cap(m.buf)) - if com < size && size < res { + if com < size && size <= res { // Round up to the page size. rnd := uint64(unix.Getpagesize() - 1) new := (size + rnd) &^ rnd diff --git a/internal/alloc/alloc_windows.go b/internal/alloc/alloc_windows.go index 27d875f..62d4996 100644 --- a/internal/alloc/alloc_windows.go +++ b/internal/alloc/alloc_windows.go @@ -48,7 +48,7 @@ type virtualMemory struct { func (m *virtualMemory) Reallocate(size uint64) []byte { com := uint64(len(m.buf)) res := uint64(cap(m.buf)) - if com < size && size < res { + if com < size && size <= res { // Round up to the page size. rnd := uint64(windows.Getpagesize() - 1) new := (size + rnd) &^ rnd