mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 01:27:03 -05:00
Fix potential memory leak
This commit is contained in:
parent
033d2264ff
commit
c89828e1fb
@ -117,7 +117,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
return nil
|
||||
}
|
||||
|
||||
var tReader buf.Reader
|
||||
var tConn net.Conn
|
||||
responseDone := func() error {
|
||||
defer timer.SetTimeout(plcy.Timeouts.UplinkOnly)
|
||||
|
||||
@ -136,14 +136,16 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
sockopt.BindAddress = dest.Address.IP()
|
||||
sockopt.BindPort = uint32(dest.Port)
|
||||
}
|
||||
tConn, err := internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
|
||||
var err error
|
||||
tConn, err = internet.DialSystem(ctx, net.DestinationFromAddr(conn.RemoteAddr()), sockopt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writer = &buf.SequentialWriter{Writer: tConn}
|
||||
tReader = buf.NewReader(tConn)
|
||||
tReader := buf.NewReader(tConn)
|
||||
go func() {
|
||||
defer tConn.Close()
|
||||
defer common.Close(link.Writer)
|
||||
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
||||
newError("failed to transport request (TPROXY conn)").Base(err).WriteToLog()
|
||||
}
|
||||
@ -151,6 +153,11 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if tConn != nil {
|
||||
tConn.Close()
|
||||
}
|
||||
}()
|
||||
if err := buf.Copy(link.Reader, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to transport response").Base(err)
|
||||
}
|
||||
@ -161,8 +168,8 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||
if err := task.Run(ctx, task.OnSuccess(requestDone, task.Close(link.Writer)), responseDone); err != nil {
|
||||
common.Interrupt(link.Reader)
|
||||
common.Interrupt(link.Writer)
|
||||
if tReader != nil {
|
||||
common.Interrupt(tReader)
|
||||
if tConn != nil {
|
||||
tConn.Close()
|
||||
}
|
||||
return newError("connection ends").Base(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user