Index: boost/asio/ssl/detail/openssl_stream_service.hpp =================================================================== --- boost/asio/ssl/detail/openssl_stream_service.hpp (revision 58104) +++ boost/asio/ssl/detail/openssl_stream_service.hpp (working copy) @@ -21,11 +21,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -57,8 +57,7 @@ void (const boost::system::error_code&, size_t)> func_t; base_handler(boost::asio::io_service& io_service) - : op_(NULL) - , io_service_(io_service) + : io_service_(io_service) , work_(io_service) {} @@ -67,17 +66,10 @@ func_(error, size); } - void set_operation(openssl_operation* op) { op_ = op; } void set_func(func_t func) { func_ = func; } - ~base_handler() - { - delete op_; - } - private: func_t func_; - openssl_operation* op_; boost::asio::io_service& io_service_; boost::asio::io_service::work work_; }; // class base_handler @@ -101,7 +93,6 @@ Handler handler_; void handler_impl(const boost::system::error_code& error, size_t size) { - std::auto_ptr > this_ptr(this); handler_(error, size); } }; // class io_handler @@ -125,7 +116,6 @@ Handler handler_; void handler_impl(const boost::system::error_code& error, size_t) { - std::auto_ptr > this_ptr(this); handler_(error); } @@ -150,7 +140,6 @@ Handler handler_; void handler_impl(const boost::system::error_code& error, size_t) { - std::auto_ptr > this_ptr(this); handler_(error); } }; // class shutdown_handler @@ -244,28 +233,29 @@ { typedef handshake_handler connect_handler; - connect_handler* local_handler = - new connect_handler(handler, get_io_service()); + boost::shared_ptr local_handler( + new connect_handler(handler, get_io_service())); - openssl_operation* op = new openssl_operation - ( - type == stream_base::client ? - &ssl_wrap::SSL_connect: - &ssl_wrap::SSL_accept, - next_layer, - impl->recv_buf, - impl->ssl, - impl->ext_bio, - boost::bind + boost::shared_ptr > op( + new openssl_operation ( - &base_handler::do_func, - local_handler, - boost::arg<1>(), - boost::arg<2>() - ), - strand_ + type == stream_base::client ? + &ssl_wrap::SSL_connect: + &ssl_wrap::SSL_accept, + next_layer, + impl->recv_buf, + impl->ssl, + impl->ext_bio, + boost::bind + ( + &base_handler::do_func, + local_handler, + boost::arg<1>(), + boost::arg<2>() + ), + strand_ + ) ); - local_handler->set_operation(op); strand_.post(boost::bind(&openssl_operation::start, op)); } @@ -301,26 +291,27 @@ { typedef shutdown_handler disconnect_handler; - disconnect_handler* local_handler = - new disconnect_handler(handler, get_io_service()); + boost::shared_ptr local_handler( + new disconnect_handler(handler, get_io_service())); - openssl_operation* op = new openssl_operation - ( - &ssl_wrap::SSL_shutdown, - next_layer, - impl->recv_buf, - impl->ssl, - impl->ext_bio, - boost::bind + boost::shared_ptr > op( + new openssl_operation ( - &base_handler::do_func, - local_handler, - boost::arg<1>(), - boost::arg<2>() - ), - strand_ + &ssl_wrap::SSL_shutdown, + next_layer, + impl->recv_buf, + impl->ssl, + impl->ext_bio, + boost::bind + ( + &base_handler::do_func, + local_handler, + boost::arg<1>(), + boost::arg<2>() + ), + strand_ + ) ); - local_handler->set_operation(op); strand_.post(boost::bind(&openssl_operation::start, op)); } @@ -367,7 +358,8 @@ { typedef io_handler send_handler; - send_handler* local_handler = new send_handler(handler, get_io_service()); + boost::shared_ptr local_handler( + new send_handler(handler, get_io_service())); std::size_t buffer_size = boost::asio::buffer_size(*buffers.begin()); if (buffer_size > max_buffer_size) @@ -378,23 +370,24 @@ boost::asio::buffer_cast(*buffers.begin()), static_cast(buffer_size)); - openssl_operation* op = new openssl_operation - ( - send_func, - next_layer, - impl->recv_buf, - impl->ssl, - impl->ext_bio, - boost::bind + boost::shared_ptr > op( + new openssl_operation ( - &base_handler::do_func, - local_handler, - boost::arg<1>(), - boost::arg<2>() - ), - strand_ + send_func, + next_layer, + impl->recv_buf, + impl->ssl, + impl->ext_bio, + boost::bind + ( + &base_handler::do_func, + local_handler, + boost::arg<1>(), + boost::arg<2>() + ), + strand_ + ) ); - local_handler->set_operation(op); strand_.post(boost::bind(&openssl_operation::start, op)); } @@ -441,7 +434,8 @@ { typedef io_handler recv_handler; - recv_handler* local_handler = new recv_handler(handler, get_io_service()); + boost::shared_ptr local_handler( + new recv_handler(handler, get_io_service())); std::size_t buffer_size = boost::asio::buffer_size(*buffers.begin()); if (buffer_size > max_buffer_size) @@ -452,23 +446,24 @@ boost::asio::buffer_cast(*buffers.begin()), static_cast(buffer_size)); - openssl_operation* op = new openssl_operation - ( - recv_func, - next_layer, - impl->recv_buf, - impl->ssl, - impl->ext_bio, - boost::bind + boost::shared_ptr > op( + new openssl_operation ( - &base_handler::do_func, - local_handler, - boost::arg<1>(), - boost::arg<2>() - ), - strand_ + recv_func, + next_layer, + impl->recv_buf, + impl->ssl, + impl->ext_bio, + boost::bind + ( + &base_handler::do_func, + local_handler, + boost::arg<1>(), + boost::arg<2>() + ), + strand_ + ) ); - local_handler->set_operation(op); strand_.post(boost::bind(&openssl_operation::start, op)); } Index: boost/asio/ssl/detail/openssl_operation.hpp =================================================================== --- boost/asio/ssl/detail/openssl_operation.hpp (revision 58104) +++ boost/asio/ssl/detail/openssl_operation.hpp (working copy) @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,7 @@ // template class openssl_operation + : public boost::enable_shared_from_this > { public: @@ -321,7 +323,7 @@ boost::bind ( &openssl_operation::async_write_handler, - this, + openssl_operation::shared_from_this(), is_operation_done, rc, boost::asio::placeholders::error, @@ -386,7 +388,7 @@ boost::bind ( &openssl_operation::async_read_handler, - this, + openssl_operation::shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred )