- Valgrind的認定問題:
==3335==
==3335== HEAP SUMMARY:
==3335== in use at exit: 2,271,338,496 bytes in 2,218,104 blocks
==3335== total heap usage: 2,218,105 allocs, 0 frees, 2,271,338,496 bytes allocated
==3335==
==3335==
==3335== Valgrind's memory management: out of memory:
==3335== newSuperblock's request for 8876032 bytes failed.
==3335== 3116339200 bytes have already been allocated.
==3335== Valgrind cannot continue. Sorry.
==3335==
==3335== There are several possible reasons for this.
==3335== - You have some kind of memory limit in place. Look at the
==3335== output of 'ulimit -a'. Is there a limit on the size of
==3335== virtual memory or address space?
==3335== - You have run out of swap space.`
即使使用O2 O3不會刪除錯誤。這是一個完整的樣本嗎?
UPD
標誌沒有改變輸出,但如果我在飛機墜毀前中斷程序,Valgrind的旁邊會顯示:
^C1890 mb
==3286==
==3286== HEAP SUMMARY:
==3286== in use at exit: 1,981,808,640 bytes in 1,935,360 blocks
==3286== total heap usage: 1,935,360 allocs, 0 frees, 1,981,808,640 bytes allocated
==3286==
==3286== 276,480 bytes in 270 blocks are possibly lost in loss record 2 of 3
==3286== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3286== by 0x8048472: main (mem_test.c:13)
==3286==
==3286== 1,981,530,112 bytes in 1,935,088 blocks are definitely lost in loss record 3 of 3
==3286== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3286== by 0x8048472: main (mem_test.c:13)
==3286==
==3286== LEAK SUMMARY:
==3286== definitely lost: 1,981,530,112 bytes in 1,935,088 blocks
==3286== indirectly lost: 0 bytes in 0 blocks
==3286== possibly lost: 276,480 bytes in 270 blocks
==3286== still reachable: 2,048 bytes in 2 blocks
==3286== suppressed: 0 bytes in 0 blocks
==3286== Reachable blocks (those to which a pointer was found) are not shown.
==3286== To see them, rerun with: --leak-check=full --show-reachable=yes
==3286==
==3286== For counts of detected and suppressed errors, rerun with: -v
==3286== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
也許是因爲編譯器計算出該內存從'返回malloc'永遠不會被使用,因此只需跳過編譯該代碼段? – Cyclonecode 2013-05-06 15:26:14
我投了+1,因爲我認爲這是一個有趣的問題,我真的很想知道答案=) – Cyclonecode 2013-05-07 17:03:56
您正在使用哪種編譯器? – Cyclonecode 2013-05-09 04:37:20