2011-08-26 62 views
0

看到我只是使用valgrind来检测代码中的内存泄漏。所以我用在valgrind输出中需要帮助了解

valgrind -v --leak-check=full --show-reachable=yes ./my_binary 

我看到下面出来,我无法理解

`==16545== 
==16545== HEAP SUMMARY: 
==16545==  in use at exit: 20,171 bytes in 647 blocks 
==16545== total heap usage: 993 allocs, 346 frees, 30,090 bytes allocated 
==16545== 
==16545== Searching for pointers to 647 not-freed blocks 
==16545== Checked 124,548 bytes 
==16545== 
==16545== 1 bytes in 1 blocks are still reachable in loss record 1 of 253 
==16545== at 0x400677E: malloc (vg_replace_malloc.c:195) 
==16545== by 0x80AAB31: xmalloc (in /bin/bash) 
==16545== by 0x80796D0: make_variable_value (in /bin/bash) 
==16545== by 0x80798C8: ??? (in /bin/bash) 
==16545== by 0x807BA40: initialize_shell_variables (in /bin/bash) 
==16545== by 0x805E897: ??? (in /bin/bash) 
==16545== by 0x805FA10: main (in /bin/bash) 
==16545== 
==16545== 1 bytes in 1 blocks are still reachable in loss record 2 of 253 
==16545== at 0x400677E: malloc (vg_replace_malloc.c:195) 
==16545== by 0x80AAB31: xmalloc (in /bin/bash) 
==16545== by 0x80A578B: set_locale_var (in /bin/bash) 
==16545== by 0x80A5912: set_default_lang (in /bin/bash) 
==16545== by 0x805FA15: main (in /bin/bash) 
==16545== 
==16545== 1 bytes in 1 blocks are still reachable in loss record 3 of 253 
==16545== at 0x400677E: malloc (vg_replace_malloc.c:195) 
==16545== by 0x80AAB31: xmalloc (in /bin/bash) 
==16545== by 0x8061B9B: ??? (in /bin/bash) 
==16545== by 0x8062D95: ??? (in /bin/bash) 
==16545== by 0x8065481: ??? (in /bin/bash) 
==16545== by 0x806801A: yyparse (in /bin/bash) 
==16545== by 0x8060580: parse_command (in /bin/bash) 
==16545== by 0x806064F: read_command (in /bin/bash) 
==16545== by 0x80608AE: reader_loop (in /bin/bash) 
==16545== by 0x805FEFB: main (in /bin/bash)`e 

我只是想明白这一点? 为什么这并没有给我特定的行号在没有释放的ma代码中?

回答

4

这些错误来自/bin/bash,不是来自您自己的代码。你是否在你的代码中运行任何bash脚本? Here是解释它的含义。我想你可以忽略它。 “

”仍然可达“意味着您的程序可能没问题 - 它没有免费提供 某些内存。这是相当普遍而且经常合理的。 如果您不想看到这些报告,请勿使用--show-reachable = yes。

+1

或者,你是不小心valgrinding编译的程序而不是程序本身的shell包装? – aschepler

+0

雅我已经做了一个shell脚本来运行ma程序 –

+0

哦,我明白了...........非常感谢你,我使用该脚本来编译该程序,然后我需要运行ma binarary,但我在这里给脚本名称...谢谢你 –

1

看起来这些地址属于您的程序代码。也许编译调试信息可以让valgrind看到行号。 (提示:gcc上的-g开关)

+0

我已经使用-g标志虽然compaling,但我仍然得到这 –

0

如果你想检查的自动工具供电编译的结果(它真的在你的build目录创建一个shell脚本),你可能会想,而不是尝试:

libtool --mode=execute valgrind -v --leak-check=full --show-reachable=yes ./my_binary