これは私がこれらの場合に使用するものです:
valgrind --track-origins=yes
use-after-freeの場合、メモリを解放した/オブジェクトを削除した関数のスタックトレースが表示されます。
警告、特にパフォーマンスに関する警告については、Valgrindのマンページをお読みください。問題が同時実行性の問題である場合、Valgrindが遅いと、プログラムのタイミングプロパティが変更され、バグが発生する可能性が変わる(減少または増加)可能性があります。
--track-origins=<yes|no> [default: no]
Controls whether Memcheck tracks the origin of uninitialised
values. By default, it does not, which means that although it can
tell you that an uninitialised value is being used in a dangerous
way, it cannot tell you where the uninitialised value came from.
This often makes it difficult to track down the root problem.
When set to yes, Memcheck keeps track of the origins of all
uninitialised values. Then, when an uninitialised value error is
reported, Memcheck will try to show the origin of the value. An
origin can be one of the following four places: a heap block, a
stack allocation, a client request, or miscellaneous other sources
(eg, a call to brk).
For uninitialised values originating from a heap block, Memcheck
shows where the block was allocated. For uninitialised values
originating from a stack allocation, Memcheck can tell you which
function allocated the value, but no more than that -- typically it
shows you the source location of the opening brace of the function.
So you should carefully check that all of the function's local
variables are initialised properly.
Performance overhead: origin tracking is expensive. It halves
Memcheck's speed and increases memory use by a minimum of 100MB,
and possibly more. Nevertheless it can drastically reduce the
effort required to identify the root cause of uninitialised value
errors, and so is often a programmer productivity win, despite
running more slowly.
Accuracy: Memcheck tracks origins quite accurately. To avoid very
large space and time overheads, some approximations are made. It is
possible, although unlikely, that Memcheck will report an incorrect
origin, or not be able to identify any origin.
Note that the combination --track-origins=yes and
--undef-value-errors=no is nonsensical. Memcheck checks for and
rejects this combination at startup.