Hello,
I've noticed that WaitHandler can be called after boost::asio::deadline_timer destruction. It may cause using of uninitialized data. Are there any other solutions of graceful destruction of boost::asio::deadline_timer to be sure that after this destruction WaitHandler will never be called?
Example pseudo code:
class UsingDeadlineTimer
{
char some_data_accessed_from_the_wait_handler[512];
boost::asio::deadline_timer timer;
void WaitHandler(const boost::system::error_code &ec)
{
if(ec == boost::asio::error::operation_aborted)
{
return;
}
memset(some_data_accessed_from_the_wait_handler, 'E', 512); // cause the problem, because UsingDeadlineTimer may be already destroyed.
}
UsingDeadlineTimer() : timer(io_service)
{
timer.expires_at(the moment of UsingDeadlineTimer destruction);
timer.async_wait( boost::bind(&UsingDeadlineTimer::WaitHandler, this, boost::asio::placeholders::error) );
}
~UsingDeadlineTimer()
{
timer.cancel(); // but we already can be in the WaitHandler body which will access some_data_accessed_from_the_wait_handler
}
};
Thank you,
Daniel