mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 12:24:19 +00:00
fixed memory leak
This commit is contained in:
parent
8801a144a0
commit
541a49c359
15
SSUData.cpp
15
SSUData.cpp
@ -22,7 +22,7 @@ namespace ssu
|
|||||||
}
|
}
|
||||||
for (auto it: m_SentMessages)
|
for (auto it: m_SentMessages)
|
||||||
{
|
{
|
||||||
for (auto f: it.second)
|
for (auto f: it.second.fragments)
|
||||||
delete[] f;
|
delete[] f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ namespace ssu
|
|||||||
if (it != m_SentMessages.end ())
|
if (it != m_SentMessages.end ())
|
||||||
{
|
{
|
||||||
// delete all ack-ed message's fragments
|
// delete all ack-ed message's fragments
|
||||||
for (auto f: it->second)
|
for (auto f: it->second.fragments)
|
||||||
delete[] f;
|
delete[] f;
|
||||||
m_SentMessages.erase (it);
|
m_SentMessages.erase (it);
|
||||||
}
|
}
|
||||||
@ -59,8 +59,7 @@ namespace ssu
|
|||||||
{
|
{
|
||||||
uint32_t msgID = be32toh (*(uint32_t *)buf);
|
uint32_t msgID = be32toh (*(uint32_t *)buf);
|
||||||
buf += 4; // msgID
|
buf += 4; // msgID
|
||||||
auto it = m_SentMessages.find (msgID);
|
auto it = m_SentMessages.find (msgID);
|
||||||
int numSentFragments = it->second.size ();
|
|
||||||
// process individual Ack bitfields
|
// process individual Ack bitfields
|
||||||
bool isNonLast = false;
|
bool isNonLast = false;
|
||||||
int fragment = 0;
|
int fragment = 0;
|
||||||
@ -71,6 +70,7 @@ namespace ssu
|
|||||||
bitfield &= 0x7F; // clear MSB
|
bitfield &= 0x7F; // clear MSB
|
||||||
if (bitfield && it != m_SentMessages.end ())
|
if (bitfield && it != m_SentMessages.end ())
|
||||||
{
|
{
|
||||||
|
int numSentFragments = it->second.fragments.size ();
|
||||||
// process bits
|
// process bits
|
||||||
uint8_t mask = 0x40;
|
uint8_t mask = 0x40;
|
||||||
for (int j = 0; j < 7; j++)
|
for (int j = 0; j < 7; j++)
|
||||||
@ -79,8 +79,8 @@ namespace ssu
|
|||||||
{
|
{
|
||||||
if (fragment < numSentFragments)
|
if (fragment < numSentFragments)
|
||||||
{
|
{
|
||||||
delete[] it->second[fragment];
|
delete[] it->second.fragments[fragment];
|
||||||
it->second[fragment] = nullptr;
|
it->second.fragments[fragment] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fragment++;
|
fragment++;
|
||||||
@ -238,7 +238,8 @@ namespace ssu
|
|||||||
DeleteI2NPMessage (msg);
|
DeleteI2NPMessage (msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto fragments = m_SentMessages[msgID];
|
SentMessage& sentMessage = m_SentMessages[msgID];
|
||||||
|
auto& fragments = sentMessage.fragments;
|
||||||
msgID = htobe32 (msgID);
|
msgID = htobe32 (msgID);
|
||||||
size_t payloadSize = SSU_MTU - sizeof (SSUHeader) - 9; // 9 = flag + #frg(1) + messageID(4) + frag info (3)
|
size_t payloadSize = SSU_MTU - sizeof (SSUHeader) - 9; // 9 = flag + #frg(1) + messageID(4) + frag info (3)
|
||||||
size_t len = msg->GetLength ();
|
size_t len = msg->GetLength ();
|
||||||
|
@ -49,6 +49,13 @@ namespace ssu
|
|||||||
IncompleteMessage (I2NPMessage * m): msg (m), nextFragmentNum (0) {};
|
IncompleteMessage (I2NPMessage * m): msg (m), nextFragmentNum (0) {};
|
||||||
~IncompleteMessage () { for (auto it: savedFragments) { delete it; }; };
|
~IncompleteMessage () { for (auto it: savedFragments) { delete it; }; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SentMessage
|
||||||
|
{
|
||||||
|
std::vector<uint8_t *> fragments;
|
||||||
|
uint32_t nextResendTime; // in seconds
|
||||||
|
int numResends;
|
||||||
|
};
|
||||||
|
|
||||||
class SSUSession;
|
class SSUSession;
|
||||||
class SSUData
|
class SSUData
|
||||||
@ -75,7 +82,7 @@ namespace ssu
|
|||||||
|
|
||||||
SSUSession& m_Session;
|
SSUSession& m_Session;
|
||||||
std::map<uint32_t, IncompleteMessage *> m_IncomleteMessages;
|
std::map<uint32_t, IncompleteMessage *> m_IncomleteMessages;
|
||||||
std::map<uint32_t, std::vector<uint8_t *> > m_SentMessages; // msgID -> fragments
|
std::map<uint32_t, SentMessage> m_SentMessages; // msgID -> fragments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user