summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-02-08 19:05:18 +0100
committerRoland Reichwein <mail@reichwein.it>2023-02-08 19:05:18 +0100
commit14b92bea172df18eb3f577e99a877fd6288379eb (patch)
treeb55b94e317881ca592ea3292039b00310225c504 /whiteboard.cpp
parent2ddb1ffe419af7189fa406978411db7d03eb8f35 (diff)
Fix crash on firing timer when object is gone already
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r--whiteboard.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp
index 2c8a47b..88f4f3b 100644
--- a/whiteboard.cpp
+++ b/whiteboard.cpp
@@ -104,6 +104,13 @@ public:
{
}
+ ~session()
+ {
+ if (m_stats_timer)
+ m_stats_timer->cancel();
+ m_stats_timer = nullptr;
+ }
+
void do_read_handshake()
{
// Set a decorator to change the Server of the handshake
@@ -273,13 +280,15 @@ public:
void stats_callback(const boost::system::error_code&)
{
- auto data{std::make_shared<std::string>(stats_xml())};
- auto buffer{std::make_shared<boost::asio::const_buffer>(data->data(), data->size())};
- m_ws->async_write(*buffer, boost::asio::bind_executor(m_ws->next_layer().get_executor(),
- boost::beast::bind_front_handler(&session::on_write_stats, shared_from_this(), data, buffer)));
+ if (m_stats_timer) {
+ auto data{std::make_shared<std::string>(stats_xml())};
+ auto buffer{std::make_shared<boost::asio::const_buffer>(data->data(), data->size())};
+ m_ws->async_write(*buffer, boost::asio::bind_executor(m_ws->next_layer().get_executor(),
+ boost::beast::bind_front_handler(&session::on_write_stats, shared_from_this(), data, buffer)));
- m_stats_timer->expires_at(m_stats_timer->expires_at() + boost::asio::chrono::seconds(5));
- m_stats_timer->async_wait(boost::beast::bind_front_handler(&session::stats_callback, this));
+ m_stats_timer->expires_at(m_stats_timer->expires_at() + boost::asio::chrono::seconds(5));
+ m_stats_timer->async_wait(boost::beast::bind_front_handler(&session::stats_callback, this));
+ }
}
void setup_stats_timer()