解释Valgrind内存泄漏总结日志
Interpreting Valgrind Memory Leak Summary Log
我正在使用Valgrind(一种内存泄漏工具)来查找潜在的内存泄漏。它是这样运行的:
$valgrind--泄漏检查=已满/myApp
报告如下:
==9458== 15,007 bytes in 126 blocks are possibly lost in loss record 622 of 622
==9458== at 0x4029FDE: operator new(unsigned int) (vg_replace_malloc.c:313)
==9458== by 0x415F213: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19)
==9458== by 0x4161125: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19)
==9458== by 0x41617AF: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.19)
==9458== by 0x808B061: Parser::parseLinear(rapidxml::xml_node<char>*, Linear*) (Parser.cpp:663)
==9458==
==9458== LEAK SUMMARY:
==9458== definitely lost: 0 bytes in 0 blocks
==9458== indirectly lost: 0 bytes in 0 blocks
==9458== possibly lost: 20,747 bytes in 257 blocks
==9458== still reachable: 57,052 bytes in 3,203 blocks
==9458== suppressed: 0 bytes in 0 blocks
==9458== Reachable blocks (those to which a pointer was found) are not shown.
==9458== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9458==
==9458== For counts of detected and suppressed errors, rerun with: -v
==9458== ERROR SUMMARY: 21 errors from 21 contexts (suppressed: 0 from 0)
根据总结,似乎存在"可能丢失"的内存泄漏。然而,在Parser.cpp中追踪到663行之后,我似乎无法确定问题所在。xml_node<>*是开源库RapidXML的一部分。源代码如下:
line 661: Tracker track;
line 662: xml_node<>* trackingNode = node->first_node(); // rapidxml API
line 663: track.setValue(trackingNode->first_node()->value());
其中setValue定义为:
void Tracker::setValue(const string& s) {
this->val = s;
}
根据rapidxml手册,xml_base::value()
不会使用rapidxml::parse_no_string_terminators
选项返回以零结尾的字符串。
如果设置了此选项,则根据xml_base::value_size()
终止字符串。
此外,在调用xml_base::value()之前,请检查该值是否为空。在其他情况下,value()返回空字符串,这可能是另一个内存泄漏问题。
相关文章:
- valgrind-hellgrind与泄漏检查的结果不同
- 从构造函数抛出异常时如何克服内存泄漏
- malloc() 可能出现内存泄漏
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 尽管遵循了规则,内存泄漏在哪里
- 为什么调用堆栈数组会导致内存泄漏
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 使用模板类的自定义列表类型中的内存泄漏
- 为什么以下C++代码中存在内存泄漏?
- Klocwork Inside的资源泄漏
- 是否可以配置提升日志刷新?
- OpenCV 我应该使用智能指针来防止内存泄漏吗?
- 我是否生成线程并导致内存泄漏?
- 跟踪日志中的T.11803()是什么意思?
- 避免Boost日志中的泄漏—琐碎的使用
- 使用boost日志,Valgrind检查内存泄漏
- 解释Valgrind内存泄漏总结日志
- 内存泄漏日志
- 解释DrMemory日志,内存泄漏