Merge pull request #750 from majestrate/tunnelgateway-leak

Fix Tunnel Gateway Leak
This commit is contained in:
orignal 2016-12-24 18:01:10 -05:00 committed by GitHub
commit cee9f1df95

View File

@ -20,6 +20,7 @@ namespace tunnel
TunnelGatewayBuffer::~TunnelGatewayBuffer ()
{
ClearTunnelDataMsgs ();
}
void TunnelGatewayBuffer::PutI2NPMsg (const TunnelMessageBlock& block)
@ -48,7 +49,7 @@ namespace tunnel
di[0] = block.deliveryType << 5; // set delivery type
// create fragments
std::shared_ptr<I2NPMessage> msg = block.data;
const std::shared_ptr<I2NPMessage> & msg = block.data;
size_t fullMsgLen = diLen + msg->GetLength () + 2; // delivery instructions + payload + 2 bytes length
if (fullMsgLen <= m_RemainingSize)
{
@ -115,10 +116,14 @@ namespace tunnel
m_CurrentTunnelDataMsg->len += s+7;
if (isLastFragment)
{
if(m_RemainingSize < (s+7)) {
LogPrint (eLogError, "TunnelGateway: remaining size overflow: ", m_RemainingSize, " < ", s+7);
} else {
m_RemainingSize -= s+7;
if (!m_RemainingSize)
if (m_RemainingSize == 0)
CompleteCurrentTunnelDataMessage ();
}
}
else
CompleteCurrentTunnelDataMessage ();
size += s;
@ -138,10 +143,12 @@ namespace tunnel
void TunnelGatewayBuffer::ClearTunnelDataMsgs ()
{
m_TunnelDataMsgs.clear ();
m_CurrentTunnelDataMsg = nullptr;
}
void TunnelGatewayBuffer::CreateCurrentTunnelDataMessage ()
{
m_CurrentTunnelDataMsg = nullptr;
m_CurrentTunnelDataMsg = NewI2NPShortMessage ();
m_CurrentTunnelDataMsg->Align (12);
// we reserve space for padding
@ -196,7 +203,7 @@ namespace tunnel
void TunnelGateway::SendBuffer ()
{
m_Buffer.CompleteCurrentTunnelDataMessage ();
auto tunnelMsgs = m_Buffer.GetTunnelDataMsgs ();
const auto & tunnelMsgs = m_Buffer.GetTunnelDataMsgs ();
for (auto& tunnelMsg : tunnelMsgs)
{
m_Tunnel->EncryptTunnelMsg (tunnelMsg, tunnelMsg);