I'm seeing a leak when using set_verify_callback on an ssl socket. I have a class "CClientSock" with member "boost::asio::ssl::stream m_socket;"
My CClientSock class derives from 'enable_shared_from_this
class CClientSock : public boost::enable_shared_from_this
If I call:
m_socket.set_verify_callback( boost::bind(&CClientSock::verify_certificate, shared_from_this(), _1, _2));
then my CClientSock instance is never destroyed.
If I do not call the "m_socket.set_verify_callback" then my CClientSock instance is destroyed correctly.
The code looks like this:
void CClientSock::StartPoll() { m_socket.set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_fail_if_no_peer_cert); m_socket.set_verify_callback( boost::bind(&CClientSock::verify_certificate, shared_from_this(), _1, _2)); boost::asio::ip::tcp::resolver::iterator endpoint_iterator; endpoint_iterator = ResolveAddress("xxx.xxx.xxx.xxx", nPort); boost::asio::async_connect( m_socket.lowest_layer(), endpoint_iterator, boost::bind(&CClientSock::handle_connect, shared_from_this(), boost::asio::placeholders::error)); } bool CClientSock::verify_certificate( bool preverified, boost::asio::ssl::verify_context& ctx ) { char subject_name[256]; X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle()); X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256); SYSTEMTIME st; GetLocalTime(&st); CString s; s.Format("%02d SSL Verify: %s", m_nId, subject_name); LogMsg(m_dwThreadId, &st, s, 0, NULL); return preverified; }
Is there something that has to be done in "set_verify_callback" to release a reference?