Valgrind告诉我:

==19305== 16 bytes in 1 blocks are definitely lost in loss record 19 of 179
==19305==    at 0x402842F: operator new(unsigned int)
==19305==    by 0x805273E: Loader::createLevel(int, int, std::string, Player*, int, int, int)
==19305==    by 0x80551B0: Loader::loadLevel()
==19305==    by 0x80676C2: main (main.cpp:38)

我的函数Loader:.createLevel有几个new语句。我怎么知道其中哪一个引起泄漏(即管道)?

谢谢!

附注:我很乐意发布代码,但是它太长了:/

最佳答案

-g选项传递给gccg++,以便您的可执行文件中包含调试符号。这是使用-g在二进制文件上运行valgrind的示例。

==20538== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==20538==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
==20538==    by 0x4004F7: main (test.c:8)
==20538==
==20538== LEAK SUMMARY:
==20538==    definitely lost: 4 bytes in 1 blocks.
==20538==      possibly lost: 0 bytes in 0 blocks.
==20538==    still reachable: 0 bytes in 0 blocks.
==20538==         suppressed: 0 bytes in 0 blocks.
==20538== Reachable blocks (those to which a pointer was found) are not shown.
==20538== To see them, rerun with: --show-reachable=yes

gcc -g test.c

这样,您可以看到进行分配的行。

09-06 16:55