Creating a boost::asio::ip::udp::socket crashing in LIB after updating from 1_55 to 1_62 on Windows

0

This is driving me nuts. Mainly because it happens 90% of the time, but occasionally I can get right by it.

So here's the backstory. I had compiled boost 1_55 using MSVC++ 2012, and we had been using it for quite a while. We are switching over to the 2013 toolchain finally and I've been tasked with upgrading everything.

I chose to grab the latest boost 1_62, and recompile with the 2013 32-bit toolset. The problem I'm having is that now that I've recompiled I am getting a crash on creating a udp socket.

So I have a library that we developed that we link statically. I inherit from that library and call a method that opens a UDP Port.

For the sake of the example I have changed my code to best illistrate this point:

In the class constructor I have the following:

        boost::asio::io_service test;
        boost::asio::ip::udp::socket socket(test);

        this->StartListen();

That works just fine. In StartListen, I call Init I have the following:

        boost::asio::ip::udp::endpoint listen_endpoint(
        boost::asio::ip::address::from_string(m_bindAddress), m_usPort);
    m_mcast_endpoint.reset(new boost::asio::ip::udp::endpoint(
        boost::asio::ip::address::from_string(m_sendAddress), m_usPort));
    m_socket.reset(new boost::asio::ip::udp::socket(m_ioservice));

This blows up on the m_socket.reset with this:

Unhandled exception at 0x77D798C1 (ntdll.dll) in program.exe: 0xC0000374: A heap has been corrupted (parameters: 0x77DAC8D0).

Interestly enough when I changed the example to be the immediately in the start listen like this:

  void Multicast::StartListen()
{
    boost::asio::io_service take2;
    boost::asio::ip::udp::socket socket_test(take2);

I get this:

Unhandled exception at 0x6384D4A1 in program.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000003).

I really have no idea what's going on here. I built boost with the

b2.exe --build-type=complete --stagedir=bin32 address-model=32 stage

and everything seems correct. What am I missing?

Well I've made more progress. The issue happens when you create a boost UDP socket in a library, and create a boost UDP socket in the code calling the library.

So: 
Main 
| 
| Create UDP Socket 
| 
CALL LIBRARY 
 | 
 | 
 | Create UDP SOCKET <--- Heap corruption
c++
visual-c++
boost
visual-studio-2013
boost-asio
asked on Stack Overflow Dec 22, 2016 by PhilD • edited Dec 27, 2016 by PhilD

2 Answers

1

Maybe you compile with headers of 1_55 but link with libs of 1_62

answered on Stack Overflow Dec 22, 2016 by ERWIN
0

The problem was with Boost.ASIO and using it from two separate projects. Putting the BOOST_ASIO_DISABLE_IOCP define in both project properties fixed the problem. There is probably a "better way" of using IOCP, but this solved it going forward.

answered on Stack Overflow Dec 27, 2016 by PhilD

User contributions licensed under CC BY-SA 3.0