diff options
author | iAndrew5 <abyzhynar@luxoft.com> | 2015-12-16 18:30:56 +0200 |
---|---|---|
committer | iAndrew5 <abyzhynar@luxoft.com> | 2015-12-17 15:13:11 +0200 |
commit | 0ee95cb11eabfea6a8674952625419eab27a0d40 (patch) | |
tree | 7e14827938a2bde5818ad17e3382268c193427e2 | |
parent | 01bfec94d2433631c8bc25c21f9bdbb4a65eeb2f (diff) | |
download | smartdevicelink-0ee95cb11eabfea6a8674952625419eab27a0d40.tar.gz |
hotfix/Data_race_in_ThreadedSocketConnection
Added protection for usage of the frames_to_send_ with the mutex as it's done in the other places
Relates:APPLINK-19408
-rw-r--r-- | src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc b/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc index 67e41cec2..9f01ccde3 100644 --- a/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc +++ b/src/components/transport_manager/src/transport_adapter/threaded_socket_connection.cc @@ -30,6 +30,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include <algorithm> #include <errno.h> #include <fcntl.h> #include <memory.h> @@ -231,8 +232,15 @@ void ThreadedSocketConnection::Transmit() { return; } - // send data if possible - if (!frames_to_send_.empty() && (poll_fds[0].revents | POLLOUT)) { + bool is_queue_empty = true; + { + // Check Frames queue is empty or not + sync_primitives::AutoLock auto_lock(frames_to_send_mutex_); + is_queue_empty = frames_to_send_.empty(); + } + + // Send data if possible + if (!is_queue_empty && (poll_fds[0].revents | POLLOUT)) { LOG4CXX_DEBUG(logger_, "frames_to_send_ not empty() "); // send data @@ -289,9 +297,11 @@ bool ThreadedSocketConnection::Receive() { bool ThreadedSocketConnection::Send() { LOG4CXX_AUTO_TRACE(logger_); FrameQueue frames_to_send; - frames_to_send_mutex_.Acquire(); + +{ + sync_primitives::AutoLock auto_lock(frames_to_send_mutex_); std::swap(frames_to_send, frames_to_send_); - frames_to_send_mutex_.Release(); +} size_t offset = 0; while (!frames_to_send.empty()) { |