【发布时间】:2014-11-20 07:31:28
【问题描述】:
在 ssl 套接字上使用 set_verify_callback 时出现泄漏。我有一个类“CClientSock”,成员为“boost::asio::ssl::stream m_socket;”
我的 CClientSock 类派生自 'enable_shared_from_this
类 CClientSock : public boost::enable_shared_from_this如果我打电话:
m_socket.set_verify_callback( boost::bind(&CClientSock::verify_certificate, shared_from_this(), _1, _2));那么我的 CClientSock 实例永远不会被破坏。
如果我不调用“m_socket.set_verify_callback”,那么我的 CClientSock 实例将被正确销毁。
代码如下所示:
无效 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(), 端点迭代器, boost::bind(&CClientSock::handle_connect, shared_from_this(), boost::asio::placeholders::error)); } bool CClientSock::verify_certificate( 布尔预验证, boost::asio::ssl::verify_context& ctx ) { 字符主题名称[256]; X509* 证书 = X509_STORE_CTX_get_current_cert(ctx.native_handle()); X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256); 系统时间 st; GetLocalTime(&st); CString s; s.Format("%02d SSL 验证:%s", m_nId, subject_name); LogMsg(m_dwThreadId, &st, s, 0, NULL); 返回预验证; }在“set_verify_callback”中是否需要做一些事情来释放引用?
【问题讨论】:
标签: c++ sockets boost memory-leaks boost-asio