From a50cbdedc5ffd0605c1e670610db904d6580213f Mon Sep 17 00:00:00 2001 From: KerstinKeller Date: Tue, 23 Jan 2024 10:14:26 +0100 Subject: [PATCH] [Core] Check validity of event callbacks before actually calling them. (#1325) --- ecal/core/src/readwrite/ecal_reader.cpp | 8 ++++---- ecal/core/src/readwrite/ecal_writer.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ecal/core/src/readwrite/ecal_reader.cpp b/ecal/core/src/readwrite/ecal_reader.cpp index e5853f093d..ba729666f4 100644 --- a/ecal/core/src/readwrite/ecal_reader.cpp +++ b/ecal/core/src/readwrite/ecal_reader.cpp @@ -728,7 +728,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(sub_event_connected); - if (iter != m_event_callback_map.end()) + if (iter != m_event_callback_map.end() && iter->second) { data.type = sub_event_connected; data.tid = tid_; @@ -745,7 +745,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(sub_event_update_connection); - if (iter != m_event_callback_map.end()) + if (iter != m_event_callback_map.end() && iter->second) { data.type = sub_event_update_connection; data.tid = tid_; @@ -767,7 +767,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(sub_event_disconnected); - if (iter != m_event_callback_map.end()) + if (iter != m_event_callback_map.end() && iter->second) { SSubEventCallbackData data; data.type = sub_event_disconnected; @@ -958,7 +958,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(sub_event_timeout); - if(iter != m_event_callback_map.end()) + if(iter != m_event_callback_map.end() && iter->second) { SSubEventCallbackData data; data.type = sub_event_timeout; diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 7a950d2dc0..e3c0ecae93 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -1007,7 +1007,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(pub_event_connected); - if (iter != m_event_callback_map.end()) + if (iter != m_event_callback_map.end() && iter->second) { data.type = pub_event_connected; (iter->second)(m_topic_name.c_str(), &data); @@ -1019,7 +1019,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(pub_event_update_connection); - if (iter != m_event_callback_map.end()) + if (iter != m_event_callback_map.end() && iter->second) { data.type = pub_event_update_connection; data.tid = tid_; @@ -1042,7 +1042,7 @@ namespace eCAL { const std::lock_guard lock(m_event_callback_map_sync); auto iter = m_event_callback_map.find(pub_event_disconnected); - if (iter != m_event_callback_map.end()) + if (iter != m_event_callback_map.end() && iter->second) { SPubEventCallbackData data; data.type = pub_event_disconnected;