Fix close conn

This commit is contained in:
世界 2023-03-03 16:46:49 +08:00
parent 42e1dea7d2
commit 2366835121
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 8 additions and 3 deletions

2
go.mod
View file

@ -29,7 +29,7 @@ require (
github.com/sagernet/sing v0.1.8-0.20230303052048-c875a4ffab1a github.com/sagernet/sing v0.1.8-0.20230303052048-c875a4ffab1a
github.com/sagernet/sing-dns v0.1.4 github.com/sagernet/sing-dns v0.1.4
github.com/sagernet/sing-shadowsocks v0.1.2-0.20230221080503-769c01d6bba9 github.com/sagernet/sing-shadowsocks v0.1.2-0.20230221080503-769c01d6bba9
github.com/sagernet/sing-shadowtls v0.0.0-20230221123345-78e50cd7b587 github.com/sagernet/sing-shadowtls v0.1.0
github.com/sagernet/sing-tun v0.1.2-0.20230226091124-0cdb0eed74d9 github.com/sagernet/sing-tun v0.1.2-0.20230226091124-0cdb0eed74d9
github.com/sagernet/sing-vmess v0.1.3-0.20230303082804-627cc46ae68b github.com/sagernet/sing-vmess v0.1.3-0.20230303082804-627cc46ae68b
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195 github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195

4
go.sum
View file

@ -139,8 +139,8 @@ github.com/sagernet/sing-dns v0.1.4 h1:7VxgeoSCiiazDSaXXQVcvrTBxFpOePPq/4XdgnUDN
github.com/sagernet/sing-dns v0.1.4/go.mod h1:1+6pCa48B1AI78lD+/i/dLgpw4MwfnsSpZo0Ds8wzzk= github.com/sagernet/sing-dns v0.1.4/go.mod h1:1+6pCa48B1AI78lD+/i/dLgpw4MwfnsSpZo0Ds8wzzk=
github.com/sagernet/sing-shadowsocks v0.1.2-0.20230221080503-769c01d6bba9 h1:qS39eA4C7x+zhEkySbASrtmb6ebdy5v0y2M6mgkmSO0= github.com/sagernet/sing-shadowsocks v0.1.2-0.20230221080503-769c01d6bba9 h1:qS39eA4C7x+zhEkySbASrtmb6ebdy5v0y2M6mgkmSO0=
github.com/sagernet/sing-shadowsocks v0.1.2-0.20230221080503-769c01d6bba9/go.mod h1:f3mHTy5shnVM9l8UocMlJgC/1G/zdj5FuEuVXhDinGU= github.com/sagernet/sing-shadowsocks v0.1.2-0.20230221080503-769c01d6bba9/go.mod h1:f3mHTy5shnVM9l8UocMlJgC/1G/zdj5FuEuVXhDinGU=
github.com/sagernet/sing-shadowtls v0.0.0-20230221123345-78e50cd7b587 h1:OjIXlHT2bblZfp+ciupM4xY9+Ccpj9FsuHRtKRBv+Pg= github.com/sagernet/sing-shadowtls v0.1.0 h1:05MYce8aR5xfKIn+y7xRFsdKhKt44QZTSEQW+lG5IWQ=
github.com/sagernet/sing-shadowtls v0.0.0-20230221123345-78e50cd7b587/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc= github.com/sagernet/sing-shadowtls v0.1.0/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc=
github.com/sagernet/sing-tun v0.1.2-0.20230226091124-0cdb0eed74d9 h1:tq1kc0HFj/jfhLfVC1NJI6lex2g6w2W+gVsFu6H2Kis= github.com/sagernet/sing-tun v0.1.2-0.20230226091124-0cdb0eed74d9 h1:tq1kc0HFj/jfhLfVC1NJI6lex2g6w2W+gVsFu6H2Kis=
github.com/sagernet/sing-tun v0.1.2-0.20230226091124-0cdb0eed74d9/go.mod h1:KnRkwaDHbb06zgeNPu0LQ8A+vA9myMxKEgHN1brCPHg= github.com/sagernet/sing-tun v0.1.2-0.20230226091124-0cdb0eed74d9/go.mod h1:KnRkwaDHbb06zgeNPu0LQ8A+vA9myMxKEgHN1brCPHg=
github.com/sagernet/sing-vmess v0.1.3-0.20230303082804-627cc46ae68b h1:NZeF0ATeJwe4W3gTJNeIfTB6yBxai665q1HvDOaWmmU= github.com/sagernet/sing-vmess v0.1.3-0.20230303082804-627cc46ae68b h1:NZeF0ATeJwe4W3gTJNeIfTB6yBxai665q1HvDOaWmmU=

View file

@ -109,11 +109,13 @@ func (h *ShadowsocksR) DialContext(ctx context.Context, network string, destinat
conn = h.cipher.StreamConn(h.obfs.StreamConn(conn)) conn = h.cipher.StreamConn(h.obfs.StreamConn(conn))
writeIv, err := conn.(*shadowstream.Conn).ObtainWriteIV() writeIv, err := conn.(*shadowstream.Conn).ObtainWriteIV()
if err != nil { if err != nil {
conn.Close()
return nil, err return nil, err
} }
conn = h.protocol.StreamConn(conn, writeIv) conn = h.protocol.StreamConn(conn, writeIv)
err = M.SocksaddrSerializer.WriteAddrPort(conn, destination) err = M.SocksaddrSerializer.WriteAddrPort(conn, destination)
if err != nil { if err != nil {
conn.Close()
return nil, E.Cause(err, "write request") return nil, E.Cause(err, "write request")
} }
return conn, nil return conn, nil

View file

@ -124,6 +124,7 @@ func (h *trojanDialer) DialContext(ctx context.Context, network string, destinat
} }
} }
if err != nil { if err != nil {
common.Close(conn)
return nil, err return nil, err
} }
switch N.NetworkName(network) { switch N.NetworkName(network) {

View file

@ -134,6 +134,7 @@ func (h *VLESS) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.
} }
} }
if err != nil { if err != nil {
common.Close(conn)
return nil, err return nil, err
} }
if h.xudp { if h.xudp {

View file

@ -157,6 +157,7 @@ func (h *vmessDialer) DialContext(ctx context.Context, network string, destinati
} }
} }
if err != nil { if err != nil {
common.Close(conn)
return nil, err return nil, err
} }
switch N.NetworkName(network) { switch N.NetworkName(network) {