Browse Source

Merge pull request #750 from majestrate/tunnelgateway-leak

Fix Tunnel Gateway Leak
pull/754/head
orignal 8 years ago committed by GitHub
parent
commit
cee9f1df95
  1. 17
      TunnelGateway.cpp

17
TunnelGateway.cpp

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

Loading…
Cancel
Save