LoginSignup
4
4

More than 5 years have passed since last update.

Valgrindによるメモリーリーク調査 メモ

Posted at

インストール

$ yum install valgrind

実行例

$valgrind -v --error-limit=no --leak-check=full --show-reachable=no ./hogehoe 2>&1 | tee valgrind.log
  • -v
    詳細表示
  • --error-limit=no
    エラー追跡をやめない
  • --leak-check=full
    メモリリークを最大限チェックする
  • --show-reachable=no
    still reachableをエラーをレポートに表示しない。
  • --trace-children=yes
    子プロセスまで追跡する。

結果確認

  • definitely lost
  • メモリリークしている。
  • possibly lost
    メモリリークしているかも?
  • still reachable
    解放できるメモリを解放していない。
    レポートが邪魔なら--show-reachable=yesを使用しない。
    ※"still reachable"はlibc++が自前で使うメモリプール分なので気にする必要はないらしい。
  • suppressed
    メモリリークエラーが抑制されている。
==15737== LEAK SUMMARY:
==15737==    definitely lost: 0 bytes in 0 blocks
==15737==    indirectly lost: 0 bytes in 0 blocks
==15737==      possibly lost: 0 bytes in 0 blocks
==15737==    still reachable: 8,391,702 bytes in 29 blocks
==15737==         suppressed: 0 bytes in 0 blocks
==27880== 152,222 (112 direct, 152,110 indirect) bytes in 2 blocks are definitely lost in loss record 31 of 34
==27880==    at 0x4E18140: calloc (vg_replace_malloc.c:418)
==27880==    by 0x45E747: cfg_init (confuse.c:1100)
==27880==    by 0x445D70: tr_config_load (tr_config.c:152)
==27880==    by 0x406123: main (pr_main.c:201)
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4