void TRadiusAttribute::Serialize(TStream* pStream)
{
if (NULL == pStream)
{
WrLog(Error, "Serialize: input parameter is NULL!");
return;
}
if (pStream->IsLoading())
{
*pStream >> m_bCode;
*pStream >> m_bLength;
if (m_bLength <= 2)
{
return;
}
NEW_S(m_uValue, unsigned char, m_bLength - 2);
if (NULL == m_uValue)
{
WrLog(Error, "Serialize: Memory alloc failure!");
return;
}
for (int i = 0; i < m_bLength - 2; i++)
{
*pStream >> m_uValue[i];
}
}
else
{
*pStream << m_bCode;
*pStream << m_bLength;
for (int i = 0; i < (m_bLength - 2); i++)
{
*pStream << m_uValue[i];
}
}
我们构造了一个错误的Radius消息码流,发现plat的内存迅速增长,10秒钟增长100多M,和现场情况一模一样,所以定位出问题的根本原因是代码中的异常保护机制不完善,错误的Radius码流会导致plat死循环
3 结论:解决方案及效果
加入对Serialize返回值的判断,一旦返回false时,跳出循环。
TBool CRadiusPacket::Serialize(TStream* pStream)
{
while (wLength > 2)
{
TRadiusAttribute* pAttribute = NULL;
NEW(pAttribute, TRadiusAttribute);
if (NULL == pAttribute)
{
WrLog(Error, "Serialize: memory alloc failure!");
return False;
}
if (False == pAttribute->Serialize(pStream))
{
LOGWARN("Serialize error,the Radius packet is invalid");
DELETE(pAttribute);
return False;
}
阅读(183) | 评论(0) | 转发(0) |