From 37fcc632f7fd9ce245e68fbf32663fa31a8ce610 Mon Sep 17 00:00:00 2001 From: NitroCao Date: Wed, 11 Jun 2025 11:43:47 +0800 Subject: [PATCH] fix: avoid defer for better performance --- internal/common/readlink_linux.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/common/readlink_linux.go b/internal/common/readlink_linux.go index 35ed026..ea2d467 100644 --- a/internal/common/readlink_linux.go +++ b/internal/common/readlink_linux.go @@ -38,14 +38,16 @@ func fixCount(n int, err error) (int, error) { // Readlink behaves like os.Readlink but caches the buffer passed to syscall.Readlink. func Readlink(name string) (string, error) { b := bufferPool.Get().(*[]byte) - defer bufferPool.Put(b) n, err := ignoringEINTR2(func() (int, error) { return fixCount(syscall.Readlink(name, *b)) }) if err != nil { + bufferPool.Put(b) return "", &os.PathError{Op: "readlink", Path: name, Err: err} } - return string((*b)[:n]), nil + result := string((*b)[:n]) + bufferPool.Put(b) + return result, nil }