diff options
author | Jonathan G Rennison <j.g.rennison@gmail.com> | 2020-05-06 23:41:25 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2020-06-18 19:57:34 +0200 |
commit | b0f192abc4e8bdd9f5f46f6932b8308e32b7b4b6 (patch) | |
tree | e674c48def6dcf142b798ad015d1ced4d3d460ee /src/network/core/tcp_connect.cpp | |
parent | c167648d75428e6ff93f903de65df0cab0370bb6 (diff) | |
download | openttd-b0f192abc4e8bdd9f5f46f6932b8308e32b7b4b6.tar.xz |
Fix: Racy use of flags in TCPConnecter::CheckCallbacks
conected and aborted flags are used concurrently from multiple threads.
Diffstat (limited to 'src/network/core/tcp_connect.cpp')
-rw-r--r-- | src/network/core/tcp_connect.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp index 9448acb83..b4485cfe9 100644 --- a/src/network/core/tcp_connect.cpp +++ b/src/network/core/tcp_connect.cpp @@ -66,19 +66,21 @@ void TCPConnecter::Connect() { for (auto iter = _tcp_connecters.begin(); iter < _tcp_connecters.end(); /* nothing */) { TCPConnecter *cur = *iter; - if ((cur->connected || cur->aborted) && cur->killed) { + const bool connected = cur->connected.load(); + const bool aborted = cur->aborted.load(); + if ((connected || aborted) && cur->killed) { iter = _tcp_connecters.erase(iter); if (cur->sock != INVALID_SOCKET) closesocket(cur->sock); delete cur; continue; } - if (cur->connected) { + if (connected) { iter = _tcp_connecters.erase(iter); cur->OnConnect(cur->sock); delete cur; continue; } - if (cur->aborted) { + if (aborted) { iter = _tcp_connecters.erase(iter); cur->OnFailure(); delete cur; |