Skip to content

Commit

Permalink
Fix: defer func for safeConnClose
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Oct 24, 2023
1 parent 2283f82 commit 45263aa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func (h *HTTP) DialContext(ctx context.Context, metadata *M.Metadata) (c net.Con
}
setKeepAlive(c)

defer safeConnClose(c, err)
defer func(c net.Conn) {
safeConnClose(c, err)
}(c)

err = h.shakeHand(metadata, c)
return
Expand Down
4 changes: 3 additions & 1 deletion proxy/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (ss *Shadowsocks) DialContext(ctx context.Context, metadata *M.Metadata) (c
}
setKeepAlive(c)

defer safeConnClose(c, err)
defer func(c net.Conn) {
safeConnClose(c, err)
}(c)

switch ss.obfsMode {
case "tls":
Expand Down
4 changes: 3 additions & 1 deletion proxy/socks4.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (ss *Socks4) DialContext(ctx context.Context, metadata *M.Metadata) (c net.
}
setKeepAlive(c)

defer safeConnClose(c, err)
defer func(c net.Conn) {
safeConnClose(c, err)
}(c)

err = socks4.ClientHandshake(c, metadata.DestinationAddress(), socks4.CmdConnect, ss.userID)
return
Expand Down
4 changes: 3 additions & 1 deletion proxy/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (ss *Socks5) DialContext(ctx context.Context, metadata *M.Metadata) (c net.
}
setKeepAlive(c)

defer safeConnClose(c, err)
defer func(c net.Conn) {
safeConnClose(c, err)
}(c)

var user *socks5.User
if ss.user != "" {
Expand Down

0 comments on commit 45263aa

Please sign in to comment.