Overview
Features
Download
Documentation
Community
Add-Ons & Services

Memory leak when exception happen during context creation

A general discussion forum.

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,
                                                                    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 ?
nellute
 
Posts: 4
Joined: 05 Jul 2011, 14:41

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron