Fix memory leak caused by Wireguard outbound

This commit is contained in:
jcdong98 2023-05-12 20:11:58 +08:00 committed by yuhan6665
parent cb7e081000
commit e7324700ed

View file

@ -152,6 +152,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
if err != nil { if err != nil {
return newError("failed to create TCP connection").Base(err) return newError("failed to create TCP connection").Base(err)
} }
defer conn.Close()
requestFunc = func() error { requestFunc = func() error {
defer timer.SetTimeout(p.Timeouts.DownlinkOnly) defer timer.SetTimeout(p.Timeouts.DownlinkOnly)
@ -166,6 +167,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
if err != nil { if err != nil {
return newError("failed to create UDP connection").Base(err) return newError("failed to create UDP connection").Base(err)
} }
defer conn.Close()
requestFunc = func() error { requestFunc = func() error {
defer timer.SetTimeout(p.Timeouts.DownlinkOnly) defer timer.SetTimeout(p.Timeouts.DownlinkOnly)
@ -183,6 +185,8 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
responseDonePost := task.OnSuccess(responseFunc, task.Close(link.Writer)) responseDonePost := task.OnSuccess(responseFunc, task.Close(link.Writer))
if err := task.Run(ctx, requestFunc, responseDonePost); err != nil { if err := task.Run(ctx, requestFunc, responseDonePost); err != nil {
common.Interrupt(link.Reader)
common.Interrupt(link.Writer)
return newError("connection ends").Base(err) return newError("connection ends").Base(err)
} }