2011-08-26 61 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