Skip to content

Commit

Permalink
martian: fix Connect() after extraction
Browse files Browse the repository at this point in the history
Remove defer as it has wrong scope, add deferred close to callers.
  • Loading branch information
mmatczuk committed Sep 12, 2024
1 parent ffa6e82 commit 73a96c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/martian/proxy_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func (p *proxyConn) handleConnectRequest(req *http.Request) error {
if res != nil {
defer res.Body.Close()
}
if crw != nil {
defer crw.Close()
}
if cerr != nil {
log.Errorf(ctx, "failed to CONNECT: %v", cerr)
return p.writeErrorResponse(req, cerr)
Expand Down
1 change: 0 additions & 1 deletion internal/martian/proxy_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (p *Proxy) Connect(ctx context.Context, req *http.Request, terminateTLS boo
res, cconn, cerr = p.connect(req)

if cconn != nil {
defer cconn.Close()
crw = cconn

if terminateTLS {
Expand Down
3 changes: 3 additions & 0 deletions internal/martian/proxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (p proxyHandler) handleConnectRequest(rw http.ResponseWriter, req *http.Req
if res != nil {
defer res.Body.Close()
}
if crw != nil {
defer crw.Close()
}
if cerr != nil {
log.Errorf(ctx, "failed to CONNECT: %v", cerr)
p.writeErrorResponse(rw, req, cerr)
Expand Down

0 comments on commit 73a96c2

Please sign in to comment.