From cb06b7b77953c6a8f99b99e42d84ed6a4aa8a0f4 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Tue, 16 May 2023 06:06:29 +0200 Subject: [PATCH] platform: fix minor linting issue (#1471) Signed-off-by: Edoardo Vacchi Signed-off-by: Adrian Cole Co-authored-by: Adrian Cole --- internal/platform/mremap_other.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/platform/mremap_other.go b/internal/platform/mremap_other.go index 02c8fcb7..ea3dbdfc 100644 --- a/internal/platform/mremap_other.go +++ b/internal/platform/mremap_other.go @@ -8,16 +8,31 @@ func remapCodeSegmentAMD64(code []byte, size int) ([]byte, error) { return nil, err } copy(b, code) - munmapCodeSegment(code) + mustMunmapCodeSegment(code) return b, nil } +// mustMunmapCodeSegment panics instead of returning an error to the +// application. +// +// # Why panic? +// +// It is less disruptive to the application to leak the previous block if it +// could be unmapped than to leak the new block and return an error. +// Realistically, either scenarios are pretty hard to debug, so we panic. There +// is less as the dominant runtime.GOOS (linux) doesn't use this anyway. +func mustMunmapCodeSegment(code []byte) { + if err := munmapCodeSegment(code); err != nil { + panic(err) + } +} + func remapCodeSegmentARM64(code []byte, size int) ([]byte, error) { b, err := mmapCodeSegmentARM64(size) if err != nil { return nil, err } copy(b, code) - munmapCodeSegment(code) + mustMunmapCodeSegment(code) return b, nil }