3

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:

==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.
Mat
  • 202,337
  • 40
  • 393
  • 406
Mark Li
  • 31
  • 2

1 Answers1

4

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. 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.

Community
  • 1
  • 1
John Zwinck
  • 239,568
  • 38
  • 324
  • 436