id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 12182,boost::asio async_send corrupts memory on Visual Studio 2015 x64 build,a-pavlov ,chris_kohlhoff,"Hi, I've got unexpected problem on Windows using Visual Studio 2015 x64. Problem occurs only in x64 Debug build on Visual Studio 2015. All works fine in Win32 build, Linux and Android platforms also. Seems x64 Release build also works fine. Brief description: {{{ #!div style=""font-size: 80%"" Code highlighting: {{{#!cpp boost::asio::async_write(*m_socket, buffers, make_write_handler( boost::bind(&base_connection::on_write, self(), _1, _2))); }}} }}} Line 69 in https://github.com/qmule/libed2k/blob/kad/src/base_connection.cpp I've got rewrited at least 4 bytes in member of peer_connection class. So, I set breakpoint on data write for class member and get stack when it happens. From stack I see memory corruption occurred on creation object in file win_iocp_socket_service_base.hpp:226 {{{ #!div style=""font-size: 80%"" Code highlighting: {{{#!cpp // Allocate and construct an operation to wrap the handler. typedef win_iocp_socket_send_op op; typename op::ptr p = { boost::asio::detail::addressof(handler), boost_asio_handler_alloc_helpers::allocate( sizeof(op), handler), 0 }; p.p = new (p.v) op(impl.cancel_token_, buffers, handler); }}} }}} Actually seems problem in boost::asio allocation helper, entry point in file handler_alloc_helpers.hpp:31 - since when I defined BOOST_ASIO_DISABLE_HANDLER_HOOKS to activate simple new for allocation problem was fixed: {{{ #!div style=""font-size: 80%"" Code highlighting: {{{#!cpp template inline void* allocate(std::size_t s, Handler& h) { #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS) return ::operator new(s); #else using boost::asio::asio_handler_allocate; return asio_handler_allocate(s, boost::asio::detail::addressof(h)); #endif } }}} }}} Full stack on breakpoint on memory: {{{ conn.exe!boost::asio::detail::consuming_buffers > >::consuming_buffers > >(const boost::asio::detail::consuming_buffers > > & other) Line 188 C++ conn.exe!boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> >::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> >(boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > && other) Line 165 C++ conn.exe!boost::asio::detail::win_iocp_socket_send_op > >,boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > >::win_iocp_socket_send_op > >,boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > >(std::weak_ptr cancel_token, const boost::asio::detail::consuming_buffers > > & buffers, boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > & handler) Line 49 C++ conn.exe!boost::asio::detail::win_iocp_socket_service_base::async_send > >,boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > >(boost::asio::detail::win_iocp_socket_service_base::base_implementation_type & impl, const boost::asio::detail::consuming_buffers > > & buffers, int flags, boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > & handler) Line 226 C++ conn.exe!boost::asio::stream_socket_service::async_send > >,boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > >(boost::asio::detail::win_iocp_socket_service::implementation_type & impl, const boost::asio::detail::consuming_buffers > > & buffers, int flags, boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > && handler) Line 332 C++ conn.exe!boost::asio::basic_stream_socket >::async_write_some > >,boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > >(const boost::asio::detail::consuming_buffers > > & buffers, boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> > && handler) Line 733 C++ conn.exe!boost::asio::detail::write_op >,std::list >,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> >::operator()(const boost::system::error_code & ec, unsigned __int64 bytes_transferred, int start) Line 183 C++ conn.exe!boost::asio::async_write >,std::list >,libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> >(boost::asio::basic_stream_socket > & s, const std::list > & buffers, libed2k::base_connection::allocating_handler,boost::_bi::list3 >,boost::arg<1>,boost::arg<2> > >,300> && handler) Line 624 C++ conn.exe!libed2k::base_connection::do_write(int quota) Line 69 C++ conn.exe!libed2k::peer_connection::do_write(int __formal) Line 492 C++ conn.exe!libed2k::base_connection::write_message(const std::pair,std::allocator > > & msg) Line 78 C++ conn.exe!libed2k::base_connection::write_struct(const libed2k::client_hello & t) Line 75 C++ conn.exe!libed2k::peer_connection::write_struct(libed2k::client_hello & t) Line 279 C++ conn.exe!libed2k::peer_connection::write_hello() Line 1667 C++ conn.exe!libed2k::peer_connection::on_connect(const boost::system::error_code & e) Line 1082 C++ }}} ",Bugs,new,To Be Determined,asio,Boost 1.60.0,Problem,,,