From d61a6cf4dc1d13fdfaea1f7b998c02f632d6e955 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Wed, 18 Nov 2020 08:39:53 +0200 Subject: [PATCH] Protect access to create_stream() with a mutex Multiple threads may access create_stream() for the same session simultaneously which can cause problems if the access is not protected. --- include/session.hh | 3 +++ src/session.cc | 2 ++ 2 files changed, 5 insertions(+) diff --git a/include/session.hh b/include/session.hh index b5cfec6..e72ca32 100644 --- a/include/session.hh +++ b/include/session.hh @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -47,5 +48,7 @@ namespace uvg_rtp { /* All media streams of this session */ std::unordered_map streams_; + + std::mutex session_mtx_; }; }; diff --git a/src/session.cc b/src/session.cc index 1859883..c4c6399 100644 --- a/src/session.cc +++ b/src/session.cc @@ -30,6 +30,8 @@ uvg_rtp::session::~session() uvg_rtp::media_stream *uvg_rtp::session::create_stream(int r_port, int s_port, rtp_format_t fmt, int flags) { + std::lock_guard m(session_mtx_); + uvg_rtp::media_stream *stream = nullptr; if (flags & RCE_SYSTEM_CALL_DISPATCHER) {