1

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语句。我如何知道其中哪一个导致泄漏(即线路)?

谢谢!

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

4

1 回答 1

3

-g将选项传递给gccorg++以便您的可执行文件中包含调试符号。这是使用 -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

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

于 2012-09-25T03:20:41.617 回答