mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
use unique_ptr for incomplete message
This commit is contained in:
parent
0dac2a74d3
commit
408a67f34f
15
SSUData.cpp
15
SSUData.cpp
@ -23,11 +23,7 @@ namespace transport
|
||||
SSUData::~SSUData ()
|
||||
{
|
||||
for (auto it: m_IncomleteMessages)
|
||||
if (it.second)
|
||||
{
|
||||
DeleteI2NPMessage (it.second->msg);
|
||||
delete it.second;
|
||||
}
|
||||
delete it.second;
|
||||
for (auto it: m_SentMessages)
|
||||
delete it.second;
|
||||
}
|
||||
@ -182,7 +178,7 @@ namespace transport
|
||||
// try saved fragments
|
||||
for (auto it1 = incompleteMessage->savedFragments.begin (); it1 != incompleteMessage->savedFragments.end ();)
|
||||
{
|
||||
auto savedFragment = *it1;
|
||||
auto& savedFragment = *it1;
|
||||
if (savedFragment->fragmentNum == incompleteMessage->nextFragmentNum)
|
||||
{
|
||||
memcpy (msg->buf + msg->len, savedFragment->buf, savedFragment->len);
|
||||
@ -190,7 +186,6 @@ namespace transport
|
||||
isLast = savedFragment->isLast;
|
||||
incompleteMessage->nextFragmentNum++;
|
||||
incompleteMessage->savedFragments.erase (it1++);
|
||||
delete savedFragment;
|
||||
}
|
||||
else
|
||||
break;
|
||||
@ -209,11 +204,8 @@ namespace transport
|
||||
// missing fragment
|
||||
LogPrint (eLogWarning, "Missing fragments from ", (int)incompleteMessage->nextFragmentNum, " to ", fragmentNum - 1, " of message ", msgID);
|
||||
auto savedFragment = new Fragment (fragmentNum, buf, fragmentSize, isLast);
|
||||
if (!incompleteMessage->savedFragments.insert (savedFragment).second)
|
||||
{
|
||||
if (!incompleteMessage->savedFragments.insert (std::unique_ptr<Fragment>(savedFragment)).second)
|
||||
LogPrint (eLogWarning, "Fragment ", (int)fragmentNum, " of message ", msgID, " already saved");
|
||||
delete savedFragment;
|
||||
}
|
||||
}
|
||||
isLast = false;
|
||||
}
|
||||
@ -221,6 +213,7 @@ namespace transport
|
||||
if (isLast)
|
||||
{
|
||||
// delete incomplete message
|
||||
incompleteMessage->msg = nullptr;
|
||||
delete incompleteMessage;
|
||||
m_IncomleteMessages.erase (msgID);
|
||||
// process message
|
||||
|
@ -48,7 +48,7 @@ namespace transport
|
||||
|
||||
struct FragmentCmp
|
||||
{
|
||||
bool operator() (const Fragment * f1, const Fragment * f2) const
|
||||
bool operator() (const std::unique_ptr<Fragment>& f1, const std::unique_ptr<Fragment>& f2) const
|
||||
{
|
||||
return f1->fragmentNum < f2->fragmentNum;
|
||||
};
|
||||
@ -58,10 +58,10 @@ namespace transport
|
||||
{
|
||||
I2NPMessage * msg;
|
||||
int nextFragmentNum;
|
||||
std::set<Fragment *, FragmentCmp> savedFragments;
|
||||
std::set<std::unique_ptr<Fragment>, FragmentCmp> savedFragments;
|
||||
|
||||
IncompleteMessage (I2NPMessage * m): msg (m), nextFragmentNum (0) {};
|
||||
~IncompleteMessage () { for (auto it: savedFragments) { delete it; }; };
|
||||
~IncompleteMessage () { if (msg) DeleteI2NPMessage (msg); };
|
||||
};
|
||||
|
||||
struct SentMessage
|
||||
|
Loading…
x
Reference in New Issue
Block a user