使用TinyXML时如何释放内存?

发布于 2024-12-01 01:48:45 字数 1365 浏览 2 评论 0原文

我正在检查泄漏内存。我正在与 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);


    }

欣赏。谢谢

I am looking over leak memory. I am working with Valgrind and i have some errors like:

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() 

The code is:

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);


    }

Appreciate. THX

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文