2

次の単純なコードをコンパイルするときに、-pgを有効にしてValgrindによってメモリリークが報告されました。

#include <iostream>
#include <boost/filesystem.hpp>

#define BOOST_FILESYSTEM_VERSION 3

using boost::filesystem::path;

using namespace std;

int main() {

        path ptDir;
        ptDir = "/home/foo/bar";

        if (true == is_directory((const path &)ptDir)){
                cout << "ptDir: " << ptDir << endl;
        }
}

完全なコンパイルオプションは次のとおりです。

g++ -pg -g test.cpp -lboost_system -lboost_filesystem

valgrindを実行するコマンドは次のとおりです。

valgrind --gen-suppressions=all --track-origins=yes --error-limit=no --leak-check=full --show-reachable=yes -v --trace-children=yes --track-fds=yes --log-file=vg.log ./a.out

次に、valgrindからメモリリークエラーが発生しました。

==9598== HEAP SUMMARY:
==9598==     in use at exit: 4,228 bytes in 1 blocks
==9598==   total heap usage: 136 allocs, 135 frees, 17,984 bytes allocated
==9598==
==9598== Searching for pointers to 1 not-freed blocks
==9598== Checked 130,088 bytes
==9598==
==9598== 4,228 bytes in 1 blocks are still reachable in loss record 1 of 1
==9598==    at 0x402A5E6: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==9598==    by 0x4260F44: monstartup (gmon.c:134)
==9598==    by 0xBED6B636: ???
==9598==    by 0x4E45504E: ???
==9598==
{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   fun:calloc
   fun:monstartup
   obj:*
   obj:*
}
==9598== LEAK SUMMARY:
==9598==    definitely lost: 0 bytes in 0 blocks
==9598==    indirectly lost: 0 bytes in 0 blocks
==9598==      possibly lost: 0 bytes in 0 blocks
==9598==    still reachable: 4,228 bytes in 1 blocks
==9598==         suppressed: 0 bytes in 0 blocks
==9598==
==9598== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==9598== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

これは正しいです?Ubuntu 12.04 /Kernel3.2.0-32-genericを使用しています

4

2 に答える 2

2

Valgrind FAQ :

"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.
于 2012-12-24T08:28:05.337 に答える