[英]The use of boost log, Valgrind check memory leak
Test code: 测试代码:
#include <iostream>
#include <boost/log/trivial.hpp>
using namespace std;
int main()
{
cout << "hello, world" << endl;
BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
BOOST_LOG_TRIVIAL(info) << "An informational severity message";
BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
BOOST_LOG_TRIVIAL(error) << "An error severity message";
BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
return 0;
}
Compile 编
g++ -Wall -DBOOST_LOG_DYN_LINK -o ./main.o -c ./main.cc
g++ ./main.o -o main -rdynamic -Wl,-rpath=/usr/local/lib -lpthread -lboost_log -lboost_system -lboost_thread -lboost_filesystem
valgrind --leak-check=full --show-reachable=yes --trace-children=yes --log-file=mem.log ./main
mem.log as follows: mem.log如下:
==29900== 8 bytes in 1 blocks are still reachable in loss record 1 of 6
==29900== at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==29900== by 0x4C8D04B: boost::log::v2_mt_posix::aux::this_thread::get_id() (in /usr/local/lib/libboost_log.so.1.56.0)
==29900== 8 bytes in 1 blocks are still reachable in loss record 2 of 6
==29900== at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==29900== by 0x4C8751C: boost::log::v2_mt_posix::sources::aux::get_severity_level() (in /usr/local/lib/libboost_log.so.1.56.0)
==29900== 16 bytes in 1 blocks are still reachable in loss record 3 of 6
==29900== at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==29900== by 0x511ADD2: boost::detail::add_thread_exit_function(boost::detail::thread_exit_function_base*) (in /usr/local/lib/libboost_thread.so.1.56.0)
==29900== 24 bytes in 1 blocks are still reachable in loss record 4 of 6
==29900== at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==29900== by 0x511A44C: boost::detail::make_external_thread_data() (in /usr/local/lib/libboost_thread.so.1.56.0)
==29900== 24 bytes in 1 blocks are still reachable in loss record 5 of 6
==29900== at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==29900== by 0x4C87569: boost::log::v2_mt_posix::sources::aux::get_severity_level() (in /usr/local/lib/libboost_log.so.1.56.0)
==29900== LEAK SUMMARY:
==29900== definitely lost: 0 bytes in 0 blocks.
==29900== possibly lost: 0 bytes in 0 blocks.
==29900== still reachable: 520 bytes in 6 blocks.
==29900== suppressed: 0 bytes in 0 blocks.
The only problems reported are "still reachable" ones, which are not always real problems. 报告的唯一问题是“仍然可以解决”的问题,这些问题并不总是真正的问题。 Valgrind is a great tool, but that particular category ( --show-reachable
) is not useful for most people. Valgrind是一个很棒的工具,但是该特定类别( --show-reachable
)对大多数人没有用。 You should simply stop using this option, because it isn't showing you anything you actually need to fix. 您应该简单地停止使用此选项,因为它没有显示您实际需要修复的任何内容。
From a previous discussion of the same: 从先前的相同讨论 :
"still reachable" means your program is probably ok -- it didn't free some memory it could have. “仍然可以访问”意味着您的程序可能还可以-它没有释放它可能拥有的一些内存。 This is quite common and often reasonable. 这是很常见的且通常是合理的。 Don't use --show-reachable=yes if you don't want to see these reports. 如果您不想查看这些报告,请不要使用--show-reachable = yes。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.