簡體   English   中英

Valgrind堆總結理解

[英]Valgrind heap summary understanding

我正在運行一個代碼,我遇到了錯誤

* 檢測到 glibc * /home/build/bin/../bin/OPENSUSE_12.2_X86_64/reader:損壞的雙鏈表:0x0000000003df6dc0 *

我嘗試通過 valgrind 重新運行它,以了解是否存在內存泄漏問題。 我運行它

valgrind --leak-check=full -v ./myprog

由於程序未完成並停止,valgrind 摘要如下:

 > ==5335== Process terminating with default action of signal 2 (SIGINT) > ==5335== at 0x54E4007: kill (in /lib64/libc-2.15.so) > ==5335== by 0x429473: ??? (in /bin/bash) > ==5335== by 0x42A313: wait_for (in /bin/bash) > ==5335== by 0x462BFE: execute_command_internal (in /bin/bash) > ==5335== by 0x463360: execute_command (in /bin/bash) > ==5335== by 0x41B7F0: reader_loop (in /bin/bash) > ==5335== by 0x41B4C9: main (in /bin/bash) > ==5335== > ==5335== HEAP SUMMARY: > ==5335== in use at exit: 37,513 bytes in 1,074 blocks > ==5335== total heap usage: 1,922 allocs, 848 frees, 72,605 bytes allocated > ==5335== > ==5335== Searching for pointers to 1,074 not-freed blocks > ==5335== Checked 220,224 bytes > ==5335== > ==5335== LEAK SUMMARY: > ==5335== definitely lost: 0 bytes in 0 blocks > ==5335== indirectly lost: 0 bytes in 0 blocks > ==5335== possibly lost: 0 bytes in 0 blocks > ==5335== still reachable: 37,513 bytes in 1,074 blocks > ==5335== suppressed: 0 bytes in 0 blocks > ==5335== Reachable blocks (those to which a pointer was found) are not shown. > ==5335== To see them, rerun with: --leak-check=full --show-reachable=yes > ==5335== > ==5335== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) > --5335-- > --5335-- used_suppression: 2 dl-hack3-cond-1 > ==5335== > ==5335== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

總堆使用量:1,922 個分配,848 個釋放,我想知道這里是否有問題? 但在錯誤摘要中沒有錯誤。 我想知道我是否應該關注代碼或內存泄漏中的任何問題?

這個總結基本上意味着你沒有在沒有首先釋放關聯的分配內存的情況下丟棄任何指針(將它們設置為NULL )。 當程序退出時,任何分配的內存(無論是否泄漏)都將被釋放。 但是,您是對的 - 您沒有泄漏任何內存,因此如果您的程序運行很長時間,您將不會耗盡堆空間。

理想情況下,您仍然應該嘗試自己清理 - 尋找malloc調用,而沒有任何相應的free調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM