Skip to content

Commit ba6eb8a

Browse files
skomskiFishrock123
authored andcommitted
crypto: fix memory leak in ECDH::SetPrivateKey
PR-URL: #2375 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 6a16368 commit ba6eb8a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/node_crypto.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -4568,8 +4568,12 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
45684568
if (priv == nullptr)
45694569
return env->ThrowError("Failed to convert Buffer to BN");
45704570

4571-
if (!EC_KEY_set_private_key(ecdh->key_, priv))
4571+
int result = EC_KEY_set_private_key(ecdh->key_, priv);
4572+
BN_free(priv);
4573+
4574+
if (!result) {
45724575
return env->ThrowError("Failed to convert BN to a private key");
4576+
}
45734577
}
45744578

45754579

0 commit comments

Comments
 (0)