Fixed memory leak in cClientHandle. (#3794)
This commit is contained in:
parent
9c25520b69
commit
f6bab71d05
@ -95,7 +95,7 @@ cClientHandle::cClientHandle(const AString & a_IPString, int a_ViewDistance) :
|
|||||||
m_LastPlacedSign(0, -1, 0),
|
m_LastPlacedSign(0, -1, 0),
|
||||||
m_ProtocolVersion(0)
|
m_ProtocolVersion(0)
|
||||||
{
|
{
|
||||||
m_Protocol = new cProtocolRecognizer(this);
|
m_Protocol = cpp14::make_unique<cProtocolRecognizer>(this);
|
||||||
|
|
||||||
s_ClientCount++; // Not protected by CS because clients are always constructed from the same thread
|
s_ClientCount++; // Not protected by CS because clients are always constructed from the same thread
|
||||||
m_UniqueID = s_ClientCount;
|
m_UniqueID = s_ClientCount;
|
||||||
@ -143,8 +143,7 @@ cClientHandle::~cClientHandle()
|
|||||||
SendDisconnect("Server shut down? Kthnxbai");
|
SendDisconnect("Server shut down? Kthnxbai");
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_Protocol;
|
m_Protocol.reset();
|
||||||
m_Protocol = nullptr;
|
|
||||||
|
|
||||||
LOGD("ClientHandle at %p deleted", static_cast<void *>(this));
|
LOGD("ClientHandle at %p deleted", static_cast<void *>(this));
|
||||||
}
|
}
|
||||||
@ -171,12 +170,13 @@ void cClientHandle::Destroy(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGD("%s: destroying client %p, \"%s\" @ %s", __FUNCTION__, static_cast<void *>(this), m_Username.c_str(), m_IPString.c_str());
|
LOGD("%s: destroying client %p, \"%s\" @ %s", __FUNCTION__, static_cast<void *>(this), m_Username.c_str(), m_IPString.c_str());
|
||||||
|
auto player = m_Player;
|
||||||
|
m_Self.reset();
|
||||||
{
|
{
|
||||||
cCSLock lock(m_CSState);
|
cCSLock lock(m_CSState);
|
||||||
m_State = csDestroyed;
|
m_State = csDestroyed; // Tick thread is allowed to call destructor async at any time after this
|
||||||
}
|
}
|
||||||
|
|
||||||
auto player = m_Player;
|
|
||||||
if (player != nullptr)
|
if (player != nullptr)
|
||||||
{
|
{
|
||||||
auto world = player->GetWorld();
|
auto world = player->GetWorld();
|
||||||
|
@ -405,7 +405,7 @@ private:
|
|||||||
std::unordered_set<cChunkCoords, cChunkCoordsHash> m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them)
|
std::unordered_set<cChunkCoords, cChunkCoordsHash> m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them)
|
||||||
cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client
|
cChunkCoordsList m_SentChunks; // Chunks that are currently sent to the client
|
||||||
|
|
||||||
cProtocol * m_Protocol;
|
std::unique_ptr<cProtocol> m_Protocol;
|
||||||
|
|
||||||
/** Protects m_IncomingData against multithreaded access. */
|
/** Protects m_IncomingData against multithreaded access. */
|
||||||
cCriticalSection m_CSIncomingData;
|
cCriticalSection m_CSIncomingData;
|
||||||
|
Loading…
Reference in New Issue
Block a user