diff --git a/transport/kcptun/client.go b/transport/kcptun/client.go index 56d7f39e..578b77b0 100644 --- a/transport/kcptun/client.go +++ b/transport/kcptun/client.go @@ -62,6 +62,7 @@ func (c *Client) createConn(ctx context.Context, dial DialFn) (*smux.Session, er convid := randv2.Uint32() kcpconn, err := kcp.NewConn4(convid, addr, c.block, config.DataShard, config.ParityShard, true, conn) if err != nil { + _ = conn.Close() return nil, err } kcpconn.SetStreamMode(true) @@ -86,6 +87,7 @@ func (c *Client) createConn(ctx context.Context, dial DialFn) (*smux.Session, er } if err := smux.VerifyConfig(smuxConfig); err != nil { + _ = kcpconn.Close() return nil, err } diff --git a/transport/kcptun/server.go b/transport/kcptun/server.go index 91d311ce..a0a137f7 100644 --- a/transport/kcptun/server.go +++ b/transport/kcptun/server.go @@ -64,6 +64,7 @@ func (s *Server) Serve(pc net.PacketConn, handler func(net.Conn)) error { mux, err := smux.Server(netConn, smuxConfig) if err != nil { + _ = netConn.Close() return } defer mux.Close()