Valgrind检测到分配的内存比释放的内存多,但没有泄漏。

3

我遇到了一个问题... 当我运行valgrind时,我的程序输出以下内容,这让我感到困惑:

==12919== HEAP SUMMARY:
==12919==     in use at exit: 97,820 bytes in 1 blocks
==12919==   total heap usage: 17 allocs, 16 frees, 99,388 bytes allocated
==12919==
==12919== LEAK SUMMARY:
==12919==    definitely lost: 0 bytes in 0 blocks
==12919==    indirectly lost: 0 bytes in 0 blocks
==12919==      possibly lost: 0 bytes in 0 blocks
==12919==    still reachable: 97,820 bytes in 1 blocks
==12919==         suppressed: 0 bytes in 0 blocks
==12919== Reachable blocks (those to which a pointer was found) are not shown.
==12919== To see them, rerun with: --leak-check=full --show-reachable=yes
==12919==
==12919== For counts of detected and suppressed errors, rerun with: -v
==12919== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)
2个回答

2

我发现这是由于带有"-pg"标志的编译导致的。没有它,一切都正常!


1

来自 valgrind faq

5.2. 使用Memcheck的内存泄漏检测器,“definitely lost”、“indirectly lost”、“possibly lost”、“still reachable”和“suppressed”之间有什么区别?

详细信息请参阅用户手册中的Memcheck部分。

简而言之:

"definitely lost" means your program is leaking memory -- fix those leaks!

"indirectly lost" means your program is leaking memory in a pointer-based structure. (E.g. if the root node of a binary tree is "definitely lost", all the children will be "indirectly lost".) If you fix the "definitely lost" leaks, the "indirectly lost" leaks should go away.

"possibly lost" means your program is leaking memory, unless you're doing unusual things with pointers that could cause them to point into the middle of an allocated block; see the user manual for some possible causes. Use --show-possibly-lost=no if you don't want to see these reports.

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

"suppressed" means that a leak error has been suppressed. There are some suppressions in the default suppression files. You can ignore suppressed errors.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接