mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
fixed potential memory leak
This commit is contained in:
parent
3987d5e5a0
commit
5f8356741e
39
SSU.cpp
39
SSU.cpp
@ -217,24 +217,33 @@ namespace transport
|
|||||||
for (auto it1: packets)
|
for (auto it1: packets)
|
||||||
{
|
{
|
||||||
auto packet = it1;
|
auto packet = it1;
|
||||||
if (!session || session->GetRemoteEndpoint () != packet->from) // we received packet for other session than previous
|
try
|
||||||
{
|
{
|
||||||
if (session) session->FlushData ();
|
if (!session || session->GetRemoteEndpoint () != packet->from) // we received packet for other session than previous
|
||||||
auto it = m_Sessions.find (packet->from);
|
|
||||||
if (it != m_Sessions.end ())
|
|
||||||
session = it->second;
|
|
||||||
if (!session)
|
|
||||||
{
|
{
|
||||||
session = std::make_shared<SSUSession> (*this, packet->from);
|
if (session) session->FlushData ();
|
||||||
session->WaitForConnect ();
|
auto it = m_Sessions.find (packet->from);
|
||||||
|
if (it != m_Sessions.end ())
|
||||||
|
session = it->second;
|
||||||
|
if (!session)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
session = std::make_shared<SSUSession> (*this, packet->from);
|
||||||
m_Sessions[packet->from] = session;
|
session->WaitForConnect ();
|
||||||
}
|
{
|
||||||
LogPrint ("New SSU session from ", packet->from.address ().to_string (), ":", packet->from.port (), " created");
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
|
m_Sessions[packet->from] = session;
|
||||||
|
}
|
||||||
|
LogPrint (eLogInfo, "New SSU session from ", packet->from.address ().to_string (), ":", packet->from.port (), " created");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
session->ProcessNextMessage (packet->buf, packet->len, packet->from);
|
||||||
session->ProcessNextMessage (packet->buf, packet->len, packet->from);
|
}
|
||||||
|
catch (std::exception& ex)
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "SSU: HandleReceivedPackets ", ex.what ());
|
||||||
|
if (session) session->FlushData ();
|
||||||
|
session = nullptr;
|
||||||
|
}
|
||||||
delete packet;
|
delete packet;
|
||||||
}
|
}
|
||||||
if (session) session->FlushData ();
|
if (session) session->FlushData ();
|
||||||
|
Loading…
Reference in New Issue
Block a user