Skip to content

Commit

Permalink
crypto/internal/boring: remove unnecessary struct field
Browse files Browse the repository at this point in the history
That could result in a hanging pointer.

Change-Id: I547950a3d3010e03b75f70f5f021f20124e2cef0
Reviewed-on: https://go-review.googlesource.com/c/go/+/644120
Auto-Submit: Roland Shoemaker <[email protected]>
Reviewed-by: Filippo Valsorda <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
rolandshoemaker authored and gopherbot committed Feb 16, 2025
1 parent 586e205 commit b38415d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/crypto/internal/boring/ecdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
type PublicKeyECDH struct {
curve string
key *C.GO_EC_POINT
group *C.GO_EC_GROUP
bytes []byte
}

Expand Down Expand Up @@ -59,7 +58,7 @@ func NewPublicKeyECDH(curve string, bytes []byte) (*PublicKeyECDH, error) {
return nil, errors.New("point not on curve")
}

k := &PublicKeyECDH{curve, key, group, append([]byte(nil), bytes...)}
k := &PublicKeyECDH{curve, key, append([]byte(nil), bytes...)}
// Note: Because of the finalizer, any time k.key is passed to cgo,
// that call must be followed by a call to runtime.KeepAlive(k),
// to make sure k is not collected (and finalized) before the cgo
Expand Down Expand Up @@ -122,7 +121,7 @@ func (k *PrivateKeyECDH) PublicKey() (*PublicKeyECDH, error) {
C._goboringcrypto_EC_POINT_free(pt)
return nil, err
}
pub := &PublicKeyECDH{k.curve, pt, group, bytes}
pub := &PublicKeyECDH{k.curve, pt, bytes}
// Note: Same as in NewPublicKeyECDH regarding finalizer and KeepAlive.
runtime.SetFinalizer(pub, (*PublicKeyECDH).finalize)
return pub, nil
Expand Down

0 comments on commit b38415d

Please sign in to comment.