mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-09 07:04:40 +01:00
fixed a memory leak if the CA file was not found while creating the Context (the OpenSSL context would leak)
This commit is contained in:
@@ -50,6 +50,8 @@ Context::Context(
|
|||||||
|
|
||||||
createSSLContext();
|
createSSLContext();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
int errCode = 0;
|
int errCode = 0;
|
||||||
if (!caLocation.empty())
|
if (!caLocation.empty())
|
||||||
{
|
{
|
||||||
@@ -61,7 +63,6 @@ Context::Context(
|
|||||||
if (errCode != 1)
|
if (errCode != 1)
|
||||||
{
|
{
|
||||||
std::string msg = Utility::getLastError();
|
std::string msg = Utility::getLastError();
|
||||||
SSL_CTX_free(_pSSLContext);
|
|
||||||
throw SSLContextException(std::string("Cannot load CA file/directory at ") + caLocation, msg);
|
throw SSLContextException(std::string("Cannot load CA file/directory at ") + caLocation, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +73,6 @@ Context::Context(
|
|||||||
if (errCode != 1)
|
if (errCode != 1)
|
||||||
{
|
{
|
||||||
std::string msg = Utility::getLastError();
|
std::string msg = Utility::getLastError();
|
||||||
SSL_CTX_free(_pSSLContext);
|
|
||||||
throw SSLContextException("Cannot load default CA certificates", msg);
|
throw SSLContextException("Cannot load default CA certificates", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,6 @@ Context::Context(
|
|||||||
if (errCode != 1)
|
if (errCode != 1)
|
||||||
{
|
{
|
||||||
std::string msg = Utility::getLastError();
|
std::string msg = Utility::getLastError();
|
||||||
SSL_CTX_free(_pSSLContext);
|
|
||||||
throw SSLContextException(std::string("Error loading private key from file ") + privateKeyFile, msg);
|
throw SSLContextException(std::string("Error loading private key from file ") + privateKeyFile, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +93,6 @@ Context::Context(
|
|||||||
if (errCode != 1)
|
if (errCode != 1)
|
||||||
{
|
{
|
||||||
std::string errMsg = Utility::getLastError();
|
std::string errMsg = Utility::getLastError();
|
||||||
SSL_CTX_free(_pSSLContext);
|
|
||||||
throw SSLContextException(std::string("Error loading certificate from file ") + certificateFile, errMsg);
|
throw SSLContextException(std::string("Error loading certificate from file ") + certificateFile, errMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,6 +107,12 @@ Context::Context(
|
|||||||
SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);
|
SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);
|
||||||
SSL_CTX_set_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
|
SSL_CTX_set_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
|
||||||
}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
SSL_CTX_free(_pSSLContext);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Context::Context(
|
Context::Context(
|
||||||
@@ -127,6 +131,8 @@ Context::Context(
|
|||||||
|
|
||||||
createSSLContext();
|
createSSLContext();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
int errCode = 0;
|
int errCode = 0;
|
||||||
if (!caLocation.empty())
|
if (!caLocation.empty())
|
||||||
{
|
{
|
||||||
@@ -138,7 +144,6 @@ Context::Context(
|
|||||||
if (errCode != 1)
|
if (errCode != 1)
|
||||||
{
|
{
|
||||||
std::string msg = Utility::getLastError();
|
std::string msg = Utility::getLastError();
|
||||||
SSL_CTX_free(_pSSLContext);
|
|
||||||
throw SSLContextException(std::string("Cannot load CA file/directory at ") + caLocation, msg);
|
throw SSLContextException(std::string("Cannot load CA file/directory at ") + caLocation, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +154,6 @@ Context::Context(
|
|||||||
if (errCode != 1)
|
if (errCode != 1)
|
||||||
{
|
{
|
||||||
std::string msg = Utility::getLastError();
|
std::string msg = Utility::getLastError();
|
||||||
SSL_CTX_free(_pSSLContext);
|
|
||||||
throw SSLContextException("Cannot load default CA certificates", msg);
|
throw SSLContextException("Cannot load default CA certificates", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +168,12 @@ Context::Context(
|
|||||||
SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);
|
SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);
|
||||||
SSL_CTX_set_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
|
SSL_CTX_set_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
|
||||||
}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
SSL_CTX_free(_pSSLContext);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Context::~Context()
|
Context::~Context()
|
||||||
|
|||||||
Reference in New Issue
Block a user