MacOS Xでは以前はソースからインストールしていましたが、
どうもMacPortからインストールできるようになっている様子。
$ sudo port install valgrind
とすると次のエラーが出たのでメモ。
Error: No valid Xcode installation is properly selected.
Error: Please use xcode-select to select an Xcode installation:
Error: sudo xcode-select -switch /Developer/Applications/Xcode.app/Contents/Developer # version 4.5.1
Error:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
(…以下省略…)
/ApplicationにXCodeがインストールされていない。
現状、XCodeは、/Developer/Applications/Xcode.appにインストールされている。
だから、
sudo xcode-select -switch /Developer/Applications/Xcode.app/Contents/Developer
を実行してスイッチしななさいとのこと。
$ sudo xcode-select -switch /Developer/Applications/Xcode.app/Contents/Developer
$ sudo port install valgrind
でほどなく解決。
いや、ここまで丁寧にエラーが出てくれるととても助かります。
あとは、
$ valgrind --leak-check= full
とかで、メモリリークのチェックができます。
メモリリークが発生していると次のようなレポートになります。
(…省略…)
==52218== HEAP SUMMARY:
==52218== in use at exit: 10,337 bytes in 42 blocks
==52218== total heap usage: 42 allocs, 0 frees, 10,337 bytes allocated
==52218==
==52218== 159 (32 direct, 127 indirect) bytes in 1 blocks are definitely lost in loss record 7 of 13
==52218== at 0xC713: malloc (vg_replace_malloc.c:274)
==52218== by 0x100000C0D: create (in ./island2)
==52218== by 0x100000D6E: main (in ./island2)
==52218==
==52218== LEAK SUMMARY:
==52218== definitely lost: 32 bytes in 1 blocks
==52218== indirectly lost: 127 bytes in 7 blocks
==52218== possibly lost: 0 bytes in 0 blocks
==52218== still reachable: 10,178 bytes in 34 blocks
==52218== suppressed: 0 bytes in 0 blocks
==52218== Reachable blocks (those to which a pointer was found) are not shown.
(…省略…)
メモリリークが発生していないと次のようなレポートになります。
(…省略…)
==52237== HEAP SUMMARY:
==52237== in use at exit: 10,178 bytes in 34 blocks
==52237== total heap usage: 42 allocs, 8 frees, 10,337 bytes allocated
==52237==
==52237== LEAK SUMMARY:
==52237== definitely lost: 0 bytes in 0 blocks
==52237== indirectly lost: 0 bytes in 0 blocks
==52237== possibly lost: 0 bytes in 0 blocks
==52237== still reachable: 10,178 bytes in 34 blocks
==52237== suppressed: 0 bytes in 0 blocks
==52237== Reachable blocks (those to which a pointer was found) are not shown.
==52237== To see them, rerun with: --leak-check=full --show-reachable=yes
==52237==
==52237== For counts of detected and suppressed errors, rerun with: -v
==52237== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
