Fix memory allocator issue.

Windows and unix allocators would panic when asked to allocate the maximum size.
This commit is contained in:
Nuno Cruces
2024-09-12 16:05:31 +01:00
parent 6a2827f989
commit fdfaaa8cec
2 changed files with 2 additions and 2 deletions

View File

@@ -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

View File

@@ -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