From 953097e9dcf770d6b51cfc71e11acd7bfa314f23 Mon Sep 17 00:00:00 2001 From: Fangliding Date: Fri, 27 Nov 2026 01:00:46 +0800 Subject: [PATCH] reduce alloc --- common/net/find_process_linux.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/net/find_process_linux.go b/common/net/find_process_linux.go index a4f3624bf..14f3c8a8b 100644 --- a/common/net/find_process_linux.go +++ b/common/net/find_process_linux.go @@ -15,6 +15,7 @@ import ( "github.com/vishvananda/netlink/nl" "golang.org/x/sys/unix" + "github.com/xtls/xray-core/common/bytespool" "github.com/xtls/xray-core/common/errors" ) @@ -88,8 +89,9 @@ func findSocketInode(network string, ip net.IP, port uint16) (*processSocket, er } var wildcard *processSocket + request := make([]byte, inetDiagRequestSize) for _, family := range families { - request := make([]byte, inetDiagRequestSize) + clear(request) request[0], request[1] = family, protocol states := ^uint32(0) if network == "tcp" { @@ -190,7 +192,8 @@ func processHasSocket(pid, targetLink string) bool { return false } - buffer := make([]byte, unix.PathMax) + buffer := bytespool.Alloc(unix.PathMax) + defer bytespool.Free(buffer) for _, fdEntry := range fdDir { n, err := unix.Readlink(filepath.Join(fdPath, fdEntry.Name()), buffer) if err != nil {