From b5adcacec4b6ec44a5555fa3f7333a92e0a8d5c1 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Sun, 6 Oct 2024 00:06:43 +0100 Subject: [PATCH] Don't panic on memory commit failure. (#154) --- 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 009cc1f..c05cfa7 100644 --- a/internal/alloc/alloc_unix.go +++ b/internal/alloc/alloc_unix.go @@ -47,7 +47,7 @@ func (m *mmappedMemory) Reallocate(size uint64) []byte { // Commit additional memory up to new bytes. err := unix.Mprotect(m.buf[com:new], unix.PROT_READ|unix.PROT_WRITE) if err != nil { - panic(err) + return nil } // Update committed memory. diff --git a/internal/alloc/alloc_windows.go b/internal/alloc/alloc_windows.go index 62d4996..46181b1 100644 --- a/internal/alloc/alloc_windows.go +++ b/internal/alloc/alloc_windows.go @@ -56,7 +56,7 @@ func (m *virtualMemory) Reallocate(size uint64) []byte { // Commit additional memory up to new bytes. _, err := windows.VirtualAlloc(m.addr, uintptr(new), windows.MEM_COMMIT, windows.PAGE_READWRITE) if err != nil { - panic(err) + return nil } // Update committed memory.