我正在查看泄漏记忆。我正在与Valgrind合作,我有一些错误,如:
Invalid read of size 1
==6643== at 0x4026CC4: strlen (mc_replace_strmem.c:282)
==6643== by 0x40D42DA: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
==6643== by 0x804B8AB: main
==6643== Address 0x441f895 is 13 bytes inside a block of size 45 free'd
==6643== at 0x4025504: operator delete(void*) (vg_replace_malloc.c:387)
==6643== by 0x40D1ACC: std::string::_Rep::_M_destroy(std::allocator<char> const&)
==6643== by 0x40D1B8B: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
==6643== by 0x804CE6A: TiXmlNode::~TiXmlNode()
==6643== by 0x80B6241: TiXmlText::~TiXmlText()
==6643== by 0x804D0B0: TiXmlNode::Clear()
==6643== by 0x804E13E: TiXmlElement::ClearThis()
代码是:
TiXmlHandle handle(&doc);
TiXmlElement* section,*pRoot,*pParam,*section1,*section2;
pRoot=doc.FirstChildElement("xml");
pParam=pRoot->FirstChildElement("Data");
while (pParam)
{
section = pParam->FirstChildElement("Name");
if (section)
{
const char* str= section->GetText();
long long int v;
sscanf(str, "%lld", &v);
}
欣赏。 THX