2010.02.26
LinuxTIPS – valgrindでメモリリークの検出
valgrindというプログラムでメモリリークの検出ができるらしい。
メモリリークだけではなくメモリデバッグもできるらしい。
っていうことで使ってみた。
–leak-check=fulで、メモリリークのフルチェック
そのあとに、コマンドを実行。
# valgrind –leak-check=full /etc/rc.d/init.d/httpd start
==2565== Memcheck, a memory error detector.
==2565== Copyright (C) 2002-2007, and GNU GPL’d, by Julian Seward et al.
==2565== Using LibVEX rev 1804, a library for dynamic binary translation.
==2565== Copyright (C) 2004-2007, and GNU GPL’d, by OpenWorks LLP.
==2565== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==2565== Copyright (C) 2000-2007, and GNU GPL’d, by Julian Seward et al.
==2565== For more details, rerun with: -v
==2565==
==2566==
==2566== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 1)
==2566== malloc/free: in use at exit: 33,367 bytes in 503 blocks.
==2566== malloc/free: 961 allocs, 458 frees, 48,772 bytes allocated.
==2566== For counts of detected errors, rerun with: -v
==2566== searching for pointers to 503 not-freed blocks.
==2566== checked 137,488 bytes.
==2566==
==2566== LEAK SUMMARY:
==2566== definitely lost: 0 bytes in 0 blocks.
==2566== possibly lost: 0 bytes in 0 blocks.
==2566== still reachable: 33,367 bytes in 503 blocks.
==2566== suppressed: 0 bytes in 0 blocks.
==2566== Reachable blocks (those to which a pointer was found) are not shown.
==2566== To see them, rerun with: –leak-check=full –show-reachable=yes
httpd を起動中: [ OK ]
==2565==
==2565== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 1)
==2565== malloc/free: in use at exit: 74,786 bytes in 5,357 blocks.
==2565== malloc/free: 16,721 allocs, 11,364 frees, 336,937 bytes allocated.
==2565== For counts of detected errors, rerun with: -v
==2565== searching for pointers to 5,357 not-freed blocks.
==2565== checked 172,288 bytes.
==2565==
==2565== LEAK SUMMARY:
==2565== definitely lost: 0 bytes in 0 blocks.
==2565== possibly lost: 0 bytes in 0 blocks.
==2565== still reachable: 74,786 bytes in 5,357 blocks.
==2565== suppressed: 0 bytes in 0 blocks.
==2565== Reachable blocks (those to which a pointer was found) are not shown.
==2565== To see them, rerun with: –leak-check=full –show-reachable=yes
上の結果をみてみると、
ERROR SUMMARYとLEAK SUMMARYが0なので、問題ないらしい。
もっと色々深く使えるらしいけど、
なんかdaemonとかの挙動がおかしい、メモリか?って時には上で十分かな?
ちなみに読み方はヴァルグラインドでOK?
Valgrind 3.3: Advanced Debugging and Profiling for GNU/ Linux Applications