Skip to content

Commit

Permalink
fix(Lite): nil pointer dereference caused by defer and return nil whe…
Browse files Browse the repository at this point in the history
…n could not write handshake packet
  • Loading branch information
robinbraemer committed Jan 14, 2024
1 parent 3946acd commit 6e35d73
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/edition/java/lite/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ func dialRoute(
Err: fmt.Errorf("failed to connect to backend %s: %w", backendAddr, err),
}
}
dstConn := dst
defer func() {
if err != nil {
_ = dst.Close()
_ = dstConn.Close()
}
}()

Expand Down Expand Up @@ -238,7 +239,7 @@ func dialRoute(

// Forward handshake packet as is.
if err = writePacket(dst, handshakeCtx); err != nil {
return nil, fmt.Errorf("failed to write handshake packet to backend: %w", err)
return dst, fmt.Errorf("failed to write handshake packet to backend: %w", err)
}

return dst, nil
Expand Down

0 comments on commit 6e35d73

Please sign in to comment.