私はファイル内のFIFOリスト(キュー)の純粋なC実装を開発しましたfifo.h
そしてfifo.c
、テストプログラムを書いたtestfifo.c
これをコンパイルすると、./bin/testfifo
ノード構造は次のように定義されます。list.h
。
私はOS X 10.6でValgrindを使ってプログラムを実行します。
valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./bin/testfifo
そして次の出力を得る
==54688== Memcheck, a memory error detector
==54688== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==54688== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==54688== Command: bin/testfifo
==54688==
--54688-- bin/testfifo:
--54688-- dSYM directory is missing; consider using --dsymutil=yes
==54688==
==54688== HEAP SUMMARY:
==54688== in use at exit: 88 bytes in 1 blocks
==54688== total heap usage: 11 allocs, 10 frees, 248 bytes allocated
==54688==
==54688== LEAK SUMMARY:
==54688== definitely lost: 0 bytes in 0 blocks
==54688== indirectly lost: 0 bytes in 0 blocks
==54688== possibly lost: 0 bytes in 0 blocks
==54688== still reachable: 0 bytes in 0 blocks
==54688== suppressed: 88 bytes in 1 blocks
==54688==
==54688== For counts of detected and suppressed errors, rerun with: -v
==54688== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
リークの概要によると、リークはないようですが、それでも「抑制された」リークが何なのかが気になります。また、割り当てと解放の数が一致しないので、リークがあるかどうかはわかりません。
- - 編集 - -
ランニング
valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v ./bin/testfifo
OS X 10.6ではかなり長くて分かりにくい出力が生成されるが、
valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./bin/testfifo
Linuxマシン上次の出力が得られました:
==32688== Memcheck, a memory error detector
==32688== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==32688== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==32688== Command: bin/testfifo
==32688==
==32688==
==32688== HEAP SUMMARY:
==32688== in use at exit: 0 bytes in 0 blocks
==32688== total heap usage: 10 allocs, 10 frees, 160 bytes allocated
==32688==
==32688== All heap blocks were freed -- no leaks are possible
==32688==
==32688== For counts of detected and suppressed errors, rerun with: -v
==32688== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
割り当てと解放が一致するようになりましたしたがって、OS X での追加の割り当ては、示唆されているように、何らかのシステム ライブラリによるものであると思われます。
-v
抑制された 4 つのエラーを明らかにするために、オプション付きでまったく同じコマンドを実行しましたが、簡単に理解できる新しい情報は得られませんでした。
ベストアンサー1
これらは、コード外部、(おそらく共有) ライブラリ内、または既知の誤検知のリークです。valgrind を実行すると、-v
使用された抑制について通知されます。