From 16acfd2718713a80bbf3815342f3b7924d4764b5 Mon Sep 17 00:00:00 2001 From: KerstinKeller Date: Wed, 24 Jan 2024 11:26:37 +0100 Subject: [PATCH] [Core] Fix race condition in CSampleSender::Send() #1332 (#1333) This PR protects the m_payload member variable and thus makes the Send() function reentrant, as it may be called simultaneously from different threads. Co-authored-by: Florian Reimold <11774314+FlorianReimold@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- ecal/core/src/io/udp/ecal_udp_sample_sender.cpp | 1 + ecal/core/src/io/udp/ecal_udp_sample_sender.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ecal/core/src/io/udp/ecal_udp_sample_sender.cpp b/ecal/core/src/io/udp/ecal_udp_sample_sender.cpp index 70c16a5399..6a353572f2 100644 --- a/ecal/core/src/io/udp/ecal_udp_sample_sender.cpp +++ b/ecal/core/src/io/udp/ecal_udp_sample_sender.cpp @@ -47,6 +47,7 @@ namespace eCAL { if (!m_udp_sender) return(0); + std::lock_guard const send_lock(m_payload_mutex); // return value size_t sent_sum(0); diff --git a/ecal/core/src/io/udp/ecal_udp_sample_sender.h b/ecal/core/src/io/udp/ecal_udp_sample_sender.h index afb4dc5411..5a90d2e68f 100644 --- a/ecal/core/src/io/udp/ecal_udp_sample_sender.h +++ b/ecal/core/src/io/udp/ecal_udp_sample_sender.h @@ -35,6 +35,7 @@ #endif #include +#include #include namespace eCAL @@ -51,6 +52,7 @@ namespace eCAL IO::UDP::SSenderAttr m_attr; std::shared_ptr m_udp_sender; + std::mutex m_payload_mutex; std::vector m_payload; }; }