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:
Guenter Obiltschnig
2014-10-18 17:22:07 +02:00
parent d74bd7bfa6
commit 558091d53f

View File

@@ -50,6 +50,8 @@ Context::Context(
createSSLContext();
try
{
int errCode = 0;
if (!caLocation.empty())
{
@@ -61,7 +63,6 @@ Context::Context(
if (errCode != 1)
{
std::string msg = Utility::getLastError();
SSL_CTX_free(_pSSLContext);
throw SSLContextException(std::string("Cannot load CA file/directory at ") + caLocation, msg);
}
}
@@ -72,7 +73,6 @@ Context::Context(
if (errCode != 1)
{
std::string msg = Utility::getLastError();
SSL_CTX_free(_pSSLContext);
throw SSLContextException("Cannot load default CA certificates", msg);
}
}
@@ -83,7 +83,6 @@ Context::Context(
if (errCode != 1)
{
std::string msg = Utility::getLastError();
SSL_CTX_free(_pSSLContext);
throw SSLContextException(std::string("Error loading private key from file ") + privateKeyFile, msg);
}
}
@@ -94,7 +93,6 @@ Context::Context(
if (errCode != 1)
{
std::string errMsg = Utility::getLastError();
SSL_CTX_free(_pSSLContext);
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_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
}
catch (...)
{
SSL_CTX_free(_pSSLContext);
throw;
}
}
Context::Context(
@@ -127,6 +131,8 @@ Context::Context(
createSSLContext();
try
{
int errCode = 0;
if (!caLocation.empty())
{
@@ -138,7 +144,6 @@ Context::Context(
if (errCode != 1)
{
std::string msg = Utility::getLastError();
SSL_CTX_free(_pSSLContext);
throw SSLContextException(std::string("Cannot load CA file/directory at ") + caLocation, msg);
}
}
@@ -149,7 +154,6 @@ Context::Context(
if (errCode != 1)
{
std::string msg = Utility::getLastError();
SSL_CTX_free(_pSSLContext);
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_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
}
catch (...)
{
SSL_CTX_free(_pSSLContext);
throw;
}
}
Context::~Context()