- Code: Select all
const Poco::Net::Context::Ptr ctx_ptr(new Poco::Net::Context(Poco::Net::Context::CLIENT_USE,
r_ssl_private_key,
r_ssl_cert,
"",
Poco::Net::Context::VERIFY_RELAXED,
9,
false,
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"));
For the above codes, if Exception happens (for example, the file specified are not found), it will cause memory leak.
After tracing the codes, it is found that the Context constructor calls the function Poco::Crypto::OpenSSLInitializer::initialize(). The destructor will call Poco::Crypto::OpenSSLInitializer::uninitialize() in the normal case.
However, when exeception occur inside the Context constructor, Poco::Crypto::OpenSSLInitializer::uninitialize() is NOT called.
I got around the problem by catching the exception and make a call to Poco::Crypto::OpenSSLInitializer::uninitialize(). Is this the correct way of doing it ?
OR should the Context constructor call Poco::Crypto::OpenSSLInitializer::uninitialize() before throwing an exception ?





