I came across this bug when trying to write a server using osc::ReceiverTcp, that supported multiple client connections. I was getting crashes in the OSC TCP server when disconnecting a client (in ReceiverTcp::closeConnection()).
The issue here is that std::remove_if not only moves any matching elements (which in this case is a unique_ptr<Connection>) to the end of the vector, but also "moves from" it -- which for a unique_ptr means it's set to nullptr. So later, when the iterator is dereferenced to call shutdown(), we get undefined behaviour (a crash, generally), here:
I came across this bug when trying to write a server using
osc::ReceiverTcp
, that supported multiple client connections. I was getting crashes in the OSC TCP server when disconnecting a client (inReceiverTcp::closeConnection()
).https://github.com/cinder/Cinder/blob/3f8bbc48fdb63346ba8799ec5c3ec99b95f74102/blocks/OSC/src/cinder/osc/Osc.cpp#L1608-L1611
The issue here is that
std::remove_if
not only moves any matching elements (which in this case is aunique_ptr<Connection>
) to the end of the vector, but also "moves from" it -- which for aunique_ptr
means it's set tonullptr
. So later, when the iterator is dereferenced to callshutdown()
, we get undefined behaviour (a crash, generally), here:https://github.com/cinder/Cinder/blob/3f8bbc48fdb63346ba8799ec5c3ec99b95f74102/blocks/OSC/src/cinder/osc/Osc.cpp#L1613