Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Nov 26, 2024
1 parent a496169 commit 500086c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ecdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,14 @@ func newECDHPkey3(nid C.int, bytes []byte, isPrivate bool) (C.GO_EVP_PKEY_PTR, e
defer C.go_openssl_EVP_PKEY_CTX_free(ctx)
if isPrivate {
if C.go_openssl_EVP_PKEY_private_check(ctx) != 1 {
C.go_openssl_EVP_PKEY_free(pkey)
// Match upstream error message.
return nil, errors.New("crypto/ecdh: invalid private key")
}
} else {
// Upstream Go does a partial check here, so do we.
if C.go_openssl_EVP_PKEY_public_check_quick(ctx) != 1 {
C.go_openssl_EVP_PKEY_free(pkey)
// Match upstream error message.
return nil, errors.New("crypto/ecdh: invalid public key")
}
Expand Down

0 comments on commit 500086c

Please sign in to comment.