summaryrefslogtreecommitdiff
path: root/src/network/core/tcp_connect.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-05-08 14:45:23 +0200
committerPatric Stout <github@truebrain.nl>2021-05-08 17:26:10 +0200
commit1b75a29d123db7aace2e8c2bf9c976e9ff8e89e3 (patch)
treedb650cc8ec079eefdae15c7afb2602507b901856 /src/network/core/tcp_connect.cpp
parent664a8c3e85cef684610e0fa65fb2ea587e46232f (diff)
downloadopenttd-1b75a29d123db7aace2e8c2bf9c976e9ff8e89e3.tar.xz
Fix: destroying a TCPConnecter that was still resolving made illegal writes
Basically, we should join the resolve thread before we destruct the object.
Diffstat (limited to 'src/network/core/tcp_connect.cpp')
-rw-r--r--src/network/core/tcp_connect.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index a1e369295..96c82b5af 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -32,13 +32,17 @@ TCPConnecter::TCPConnecter(const std::string &connection_string, uint16 default_
_tcp_connecters.push_back(this);
- if (!StartNewThread(nullptr, "ottd:resolve", &TCPConnecter::ResolveThunk, this)) {
+ if (!StartNewThread(&this->resolve_thread, "ottd:resolve", &TCPConnecter::ResolveThunk, this)) {
this->Resolve();
}
}
TCPConnecter::~TCPConnecter()
{
+ if (this->resolve_thread.joinable()) {
+ this->resolve_thread.join();
+ }
+
for (const auto &socket : this->sockets) {
closesocket(socket);
}
@@ -187,6 +191,7 @@ void TCPConnecter::Resolve()
this->ai = ai;
this->OnResolved(ai);
+
this->is_resolved = true;
}