diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-02-08 19:05:18 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-02-08 19:05:18 +0100 |
commit | 14b92bea172df18eb3f577e99a877fd6288379eb (patch) | |
tree | b55b94e317881ca592ea3292039b00310225c504 | |
parent | 2ddb1ffe419af7189fa406978411db7d03eb8f35 (diff) |
Fix crash on firing timer when object is gone already
-rw-r--r-- | connectionregistry.cpp | 6 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | 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<ConnectionRegistry::connection>::iterator ConnectionRegistry::begin(const std::string& id) { + if (!m_ids.contains(id)) + return std::unordered_set<ConnectionRegistry::connection>::iterator{}; + return m_ids.at(id).begin(); } std::unordered_set<ConnectionRegistry::connection>::iterator ConnectionRegistry::end(const std::string& id) { + if (!m_ids.contains(id)) + return std::unordered_set<ConnectionRegistry::connection>::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 <mail@reichwein.it> 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<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() |