Fixed possible leak in tls_prepare

If the function fails, the 'underlying' BIO was leaking as
tls_free did not clean it up if 'tls->bio' was not successfully
allocated.
This commit is contained in:
akallabeth 2021-09-17 09:03:18 +02:00 committed by akallabeth
parent 5b78d02d5d
commit 75e6f443b5
1 changed files with 5 additions and 2 deletions

View File

@ -656,6 +656,7 @@ static BOOL tls_prepare(rdpTls* tls, BIO* underlying, SSL_METHOD* method, int op
{
rdpSettings* settings = tls->settings;
tls->ctx = SSL_CTX_new(method);
tls->underlying = underlying;
if (!tls->ctx)
{
@ -692,7 +693,6 @@ static BOOL tls_prepare(rdpTls* tls, BIO* underlying, SSL_METHOD* method, int op
}
BIO_push(tls->bio, underlying);
tls->underlying = underlying;
return TRUE;
}
@ -1672,7 +1672,10 @@ void tls_free(rdpTls* tls)
/* tls->underlying is a stacked BIO under tls->bio.
* BIO_free_all will free recursivly. */
BIO_free_all(tls->bio);
if (tls->bio)
BIO_free_all(tls->bio);
else if (tls->underlying)
BIO_free_all(tls->underlying);
tls->bio = NULL;
tls->underlying = NULL;