Skip to content

Commit

Permalink
Fix memory leak in setupEVP
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Feb 8, 2024
1 parent ed177ef commit 104fe7f
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 104fe7f

Please # to comment.