Fix: windows process panic (#2793)
This commit is contained in:
parent
355eb491ad
commit
9177645a89
@ -7,8 +7,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/common/pool"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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) {
|
func findPidByConnectionEndpoint(family uint32, protocol uint32, from netip.AddrPort, to netip.AddrPort) (uint32, error) {
|
||||||
buf := pool.Get(8)
|
buf := []byte(nil)
|
||||||
defer pool.Put(buf)
|
bufSize := uint32(0)
|
||||||
|
|
||||||
bufSize := uint32(len(buf))
|
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
@ -55,7 +51,7 @@ loop:
|
|||||||
switch protocol {
|
switch protocol {
|
||||||
case windows.IPPROTO_TCP:
|
case windows.IPPROTO_TCP:
|
||||||
ret, _, _ = procGetExtendedTcpTable.Call(
|
ret, _, _ = procGetExtendedTcpTable.Call(
|
||||||
uintptr(unsafe.Pointer(&buf[0])),
|
uintptr(unsafe.Pointer(unsafe.SliceData(buf))),
|
||||||
uintptr(unsafe.Pointer(&bufSize)),
|
uintptr(unsafe.Pointer(&bufSize)),
|
||||||
0,
|
0,
|
||||||
uintptr(family),
|
uintptr(family),
|
||||||
@ -64,7 +60,7 @@ loop:
|
|||||||
)
|
)
|
||||||
case windows.IPPROTO_UDP:
|
case windows.IPPROTO_UDP:
|
||||||
ret, _, _ = procGetExtendedUdpTable.Call(
|
ret, _, _ = procGetExtendedUdpTable.Call(
|
||||||
uintptr(unsafe.Pointer(&buf[0])),
|
uintptr(unsafe.Pointer(unsafe.SliceData(buf))),
|
||||||
uintptr(unsafe.Pointer(&bufSize)),
|
uintptr(unsafe.Pointer(&bufSize)),
|
||||||
0,
|
0,
|
||||||
uintptr(family),
|
uintptr(family),
|
||||||
@ -81,8 +77,7 @@ loop:
|
|||||||
|
|
||||||
break loop
|
break loop
|
||||||
case uintptr(windows.ERROR_INSUFFICIENT_BUFFER):
|
case uintptr(windows.ERROR_INSUFFICIENT_BUFFER):
|
||||||
pool.Put(buf)
|
buf = make([]byte, bufSize)
|
||||||
buf = pool.Get(int(bufSize))
|
|
||||||
|
|
||||||
continue loop
|
continue loop
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user