Skip to content

Commit 80bcf72

Browse files
committed
ssl: fix potential memory leak in SSLContext#setup
If SSL_CTX_add_extra_chain_cert() fails, the refcount of x509 must be handled by the caller. This should only occur due to a malloc failure inside the function.
1 parent 201a5d3 commit 80bcf72

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ ossl_sslctx_add_extra_chain_cert_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
430430

431431
GetSSLCTX(arg, ctx);
432432
x509 = DupX509CertPtr(i);
433-
if(!SSL_CTX_add_extra_chain_cert(ctx, x509)){
434-
ossl_raise(eSSLError, NULL);
433+
if (!SSL_CTX_add_extra_chain_cert(ctx, x509)) {
434+
X509_free(x509);
435+
ossl_raise(eSSLError, "SSL_CTX_add_extra_chain_cert");
435436
}
436437

437438
return i;

0 commit comments

Comments
 (0)