Skip to content

Commit

Permalink
fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jul 4, 2014
1 parent 12fbc9c commit b19e6bb
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions TunnelEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,25 @@ namespace tunnel
if (fragmentNum == it->second.nextFragmentNum)
{
I2NPMessage * incompleteMessage = it->second.data;
if (incompleteMessage->len + size >= I2NP_MAX_MESSAGE_SIZE)
if (incompleteMessage->len + size < I2NP_MAX_MESSAGE_SIZE) // check if messega is not too long
{
memcpy (incompleteMessage->buf + incompleteMessage->len, fragment, size); // concatenate fragment
incompleteMessage->len += size;
if (isLastFragment)
{
// message complete
HandleNextMessage (it->second);
m_IncompleteMessages.erase (it);
}
else
it->second.nextFragmentNum++;
}
else
{
LogPrint ("Fragment ", fragmentNum, " of message ", msgID, "exceeds max I2NP message size. Message dropped");
i2p::DeleteI2NPMessage (it->second.data);
m_IncompleteMessages.erase (it);
continue;
}
memcpy (incompleteMessage->buf + incompleteMessage->len, fragment, size); // concatenate fragment
incompleteMessage->len += size;
if (isLastFragment)
{
// message complete
HandleNextMessage (it->second);
m_IncompleteMessages.erase (it);
}
else
it->second.nextFragmentNum++;
}
else
{
Expand All @@ -157,6 +159,9 @@ namespace tunnel
// last message is follow-on fragment
// not passed to anywhere because first fragment
i2p::DeleteI2NPMessage (msg);
else
// delete temporarty copy used for first fragment only
i2p::DeleteI2NPMessage (m.data);
}
}
else
Expand Down

0 comments on commit b19e6bb

Please sign in to comment.