Reuse dead connection slots.

This fixes a memory leak on multiple disconnect/reconnect of the same client.
This commit is contained in:
Peter Johnson
2015-11-01 22:47:15 -08:00
parent 03ee425e5f
commit 9f5fe63aaa

View File

@@ -306,7 +306,16 @@ void DispatcherBase::ServerThreadMain() {
std::weak_ptr<NetworkConnection>(conn)));
{
std::lock_guard<std::mutex> lock(m_user_mutex);
m_connections.emplace_back(conn);
// reuse dead connection slots
bool placed = false;
for (auto& c : m_connections) {
if (c->state() == NetworkConnection::kDead) {
c = conn;
placed = true;
break;
}
}
if (!placed) m_connections.emplace_back(conn);
conn->Start();
}
}