Skip to content

Commit

Permalink
Merge pull request #64 from microsoft/dev/dagood/fix-port
Browse files Browse the repository at this point in the history
Fix memory leak in setupEVP
  • Loading branch information
dagood authored Mar 20, 2024
2 parents ed177ef + 104fe7f commit d431ca0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions openssl/evpkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ type verifyFunc func(C.GO_EVP_PKEY_CTX_PTR, *C.uchar, C.size_t, *C.uchar, C.size

func setupEVP(withKey withKeyFunc, padding C.int,
h, mgfHash hash.Hash, label []byte, saltLen C.int, ch crypto.Hash,
init initFunc) (ctx C.GO_EVP_PKEY_CTX_PTR, err error) {
init initFunc) (_ C.GO_EVP_PKEY_CTX_PTR, err error) {
var ctx C.GO_EVP_PKEY_CTX_PTR
withKey(func(pkey C.GO_EVP_PKEY_PTR) C.int {
ctx = C.go_openssl_EVP_PKEY_CTX_new(pkey, nil)
return 1
})
if ctx == nil {
return nil, newOpenSSLError("EVP_PKEY_CTX_new failed")
}
defer func() {
if err != nil {
if ctx != nil {
Expand All @@ -110,14 +118,6 @@ func setupEVP(withKey withKeyFunc, padding C.int,
}
}
}()

withKey(func(pkey C.GO_EVP_PKEY_PTR) C.int {
ctx = C.go_openssl_EVP_PKEY_CTX_new(pkey, nil)
return 1
})
if ctx == nil {
return nil, newOpenSSLError("EVP_PKEY_CTX_new failed")
}
if err := init(ctx); err != nil {
return nil, err
}
Expand Down

0 comments on commit d431ca0

Please sign in to comment.