From daf0b23805153369425ca2d6633fc88df05dd522 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 22 Dec 2022 12:31:45 +0800 Subject: [PATCH] fix: some safeConnClose forget using original --- adapter/outbound/trojan.go | 8 ++++---- adapter/outbound/vless.go | 12 ++++++------ adapter/outbound/vmess.go | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/adapter/outbound/trojan.go b/adapter/outbound/trojan.go index e3abeab2..698db598 100644 --- a/adapter/outbound/trojan.go +++ b/adapter/outbound/trojan.go @@ -153,9 +153,9 @@ func (t *Trojan) ListenPacketContext(ctx context.Context, metadata *C.Metadata, if err != nil { return nil, fmt.Errorf("%s connect error: %w", t.addr, err) } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) err = t.instance.WriteHeader(c, trojan.CommandUDP, serializesSocksAddr(metadata)) if err != nil { return nil, err @@ -173,9 +173,9 @@ func (t *Trojan) ListenPacketWithDialer(ctx context.Context, dialer C.Dialer, me if err != nil { return nil, fmt.Errorf("%s connect error: %w", t.addr, err) } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) tcpKeepAlive(c) c, err = t.plainStream(c) if err != nil { diff --git a/adapter/outbound/vless.go b/adapter/outbound/vless.go index 5261fefd..06627912 100644 --- a/adapter/outbound/vless.go +++ b/adapter/outbound/vless.go @@ -208,9 +208,9 @@ func (v *Vless) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d if err != nil { return nil, err } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.client.StreamConn(c, parseVlessAddr(metadata)) if err != nil { @@ -255,9 +255,9 @@ func (v *Vless) ListenPacketContext(ctx context.Context, metadata *C.Metadata, o if err != nil { return nil, err } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.client.StreamConn(c, parseVlessAddr(metadata)) @@ -285,9 +285,9 @@ func (v *Vless) ListenPacketWithDialer(ctx context.Context, dialer C.Dialer, met return nil, fmt.Errorf("%s connect error: %s", v.addr, err.Error()) } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.StreamConn(c, metadata) diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 2d1bd94d..8d018caa 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -221,9 +221,9 @@ func (v *Vmess) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d if err != nil { return nil, err } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.client.DialConn(c, M.ParseSocksaddr(metadata.RemoteAddress())) if err != nil { @@ -275,9 +275,9 @@ func (v *Vmess) ListenPacketContext(ctx context.Context, metadata *C.Metadata, o if err != nil { return nil, err } - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) if v.option.XUDP { c, err = v.client.DialXUDPPacketConn(c, M.ParseSocksaddr(metadata.RemoteAddress())) @@ -295,9 +295,9 @@ func (v *Vmess) ListenPacketContext(ctx context.Context, metadata *C.Metadata, o return nil, fmt.Errorf("%s connect error: %s", v.addr, err.Error()) } tcpKeepAlive(c) - defer func() { + defer func(c net.Conn) { safeConnClose(c, err) - }() + }(c) c, err = v.StreamConn(c, metadata) return v.ListenPacketWithDialer(ctx, dialer.NewDialer(v.Base.DialOptions(opts...)...), metadata)