From 14b92bea172df18eb3f577e99a877fd6288379eb Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 8 Feb 2023 19:05:18 +0100 Subject: Fix crash on firing timer when object is gone already --- connectionregistry.cpp | 6 ++++++ debian/changelog | 6 ++++++ whiteboard.cpp | 21 +++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/connectionregistry.cpp b/connectionregistry.cpp index 412472d..5b2ea2b 100644 --- a/connectionregistry.cpp +++ b/connectionregistry.cpp @@ -53,11 +53,17 @@ void ConnectionRegistry::delConnection(ConnectionRegistry::connection c) std::unordered_set::iterator ConnectionRegistry::begin(const std::string& id) { + if (!m_ids.contains(id)) + return std::unordered_set::iterator{}; + return m_ids.at(id).begin(); } std::unordered_set::iterator ConnectionRegistry::end(const std::string& id) { + if (!m_ids.contains(id)) + return std::unordered_set::iterator{}; + return m_ids.at(id).end(); } diff --git a/debian/changelog b/debian/changelog index d2747dc..ab5babd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +whiteboard (1.7) UNRELEASED; urgency=medium + + * + + -- Roland Reichwein Wed, 08 Feb 2023 18:22:26 +0100 + whiteboard (1.6) unstable; urgency=medium * Added stats.html 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(stats_xml())}; - auto buffer{std::make_shared(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(stats_xml())}; + auto buffer{std::make_shared(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() -- cgit v1.2.3