[Boost-bugs] [Boost C++ Libraries] #12182: boost::asio async_send corrupts memory on Visual Studio 2015 x64 build

Subject: [Boost-bugs] [Boost C++ Libraries] #12182: boost::asio async_send corrupts memory on Visual Studio 2015 x64 build
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-05-08 14:19:43


#12182: boost::asio async_send corrupts memory on Visual Studio 2015 x64 build
----------------------------------+----------------------------
 Reporter: a-pavlov <dkfsoft@…> | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.60.0 | Severity: Problem
 Keywords: |
----------------------------------+----------------------------
 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<ConstBufferSequence, Handler> 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 <typename Handler>
 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<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>
>::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> >(const
 boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> > & other) Line 188 C++
 conn.exe!boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300>
>::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300>
>(boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const &,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> > && other) Line 165 C++
 conn.exe!boost::asio::detail::win_iocp_socket_send_op<boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>
>,boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> >
>::win_iocp_socket_send_op<boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>
>,boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> > >(std::weak_ptr<void>
 cancel_token, const
 boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> > & buffers,
 boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const &,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,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::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>
>,boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,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<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> > & buffers, int flags,
 boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const &,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> > & handler) Line 226 C++
 conn.exe!boost::asio::stream_socket_service<boost::asio::ip::tcp>::async_send<boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>
>,boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> >
>(boost::asio::detail::win_iocp_socket_service<boost::asio::ip::tcp>::implementation_type
 & impl, const
 boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> > & buffers, int flags,
 boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const &,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> > && handler) Line 332 C++
 conn.exe!boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>::async_write_some<boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>
>,boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> > >(const
 boost::asio::detail::consuming_buffers<boost::asio::const_buffer,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> > & buffers,
 boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const &,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300> > && handler) Line 733 C++
 conn.exe!boost::asio::detail::write_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,boost::asio::detail::transfer_all_t,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,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<boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
>,std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
>,libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const & __ptr64,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,boost::arg<1>,boost::arg<2> > >,300>
>(boost::asio::basic_stream_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>
> & s, const
 std::list<boost::asio::const_buffer,std::allocator<boost::asio::const_buffer>
> & buffers,
 libed2k::base_connection::allocating_handler<boost::_bi::bind_t<void,boost::_mfi::mf2<void,libed2k::base_connection,boost::system::error_code
 const &,unsigned
 __int64>,boost::_bi::list3<boost::_bi::value<boost::intrusive_ptr<libed2k::base_connection>
>,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<libed2k::libed2k_header,std::basic_string<char,std::char_traits<char>,std::allocator<char>
> > & msg) Line 78 C++
 conn.exe!libed2k::base_connection::write_struct<libed2k::client_hello>(const
 libed2k::client_hello & t) Line 75 C++
 conn.exe!libed2k::peer_connection::write_struct<libed2k::client_hello>(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++
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12182>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC