From 9177645a89c88dc270e69486478ad105c0f487a1 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Thu, 15 Jun 2023 21:37:26 +0800 Subject: [PATCH] Fix: windows process panic (#2793) --- component/process/process_windows.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/component/process/process_windows.go b/component/process/process_windows.go index 6ae61a3..6ccb158 100644 --- a/component/process/process_windows.go +++ b/component/process/process_windows.go @@ -7,8 +7,6 @@ import ( "unsafe" "golang.org/x/sys/windows" - - "github.com/Dreamacro/clash/common/pool" ) var ( @@ -43,10 +41,8 @@ func findProcessPath(network string, from netip.AddrPort, to netip.AddrPort) (st } func findPidByConnectionEndpoint(family uint32, protocol uint32, from netip.AddrPort, to netip.AddrPort) (uint32, error) { - buf := pool.Get(8) - defer pool.Put(buf) - - bufSize := uint32(len(buf)) + buf := []byte(nil) + bufSize := uint32(0) loop: for { @@ -55,7 +51,7 @@ loop: switch protocol { case windows.IPPROTO_TCP: ret, _, _ = procGetExtendedTcpTable.Call( - uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(unsafe.SliceData(buf))), uintptr(unsafe.Pointer(&bufSize)), 0, uintptr(family), @@ -64,7 +60,7 @@ loop: ) case windows.IPPROTO_UDP: ret, _, _ = procGetExtendedUdpTable.Call( - uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(unsafe.SliceData(buf))), uintptr(unsafe.Pointer(&bufSize)), 0, uintptr(family), @@ -81,8 +77,7 @@ loop: break loop case uintptr(windows.ERROR_INSUFFICIENT_BUFFER): - pool.Put(buf) - buf = pool.Get(int(bufSize)) + buf = make([]byte, bufSize) continue loop default: