Memory leak when exception happen during context creation

A general discussion forum.
Posts: 4
Joined: 05 Jul 2011, 14:41

Memory leak when exception happen during context creation

Postby nellute » 06 Jul 2011, 10:33

Code: Select all

        const Poco::Net::Context::Ptr ctx_ptr(new Poco::Net::Context(Poco::Net::Context::CLIENT_USE,

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 ?

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest