diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 31f469286a71c7..090c908894efd6 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4568,8 +4568,12 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo& args) { if (priv == nullptr) return env->ThrowError("Failed to convert Buffer to BN"); - if (!EC_KEY_set_private_key(ecdh->key_, priv)) + int result = EC_KEY_set_private_key(ecdh->key_, priv); + BN_free(priv); + + if (!result) { return env->ThrowError("Failed to convert BN to a private key"); + } }