C++ Sanitizers



Below is the recommended list of useful, portable, low-friction, multi-distro sanitizers.

Other sanitizers like integer, memory, HWASan did not make the list as they are not as useful or their implementation could be not supported, or give different results, for different distros / compilers, etc.

address: ASan — AddressSanitizer (-fsanitize=address)

Purpose: Detects memory safety bugs at runtime.

Typical use: “find crashes/corruption fast.”

Typical findings

How it works (conceptually)

Caveats


thread: TSan — ThreadSanitizer (-fsanitize=thread)

Detects data races and other concurrency issues:

Typical use: “validate thread safety.” Note: Usually run as a separate build from ASan.

Purpose: Detects data races and some other concurrency bugs.

Typical findings

How it works

Caveats


undefined UBSan — UndefinedBehaviorSanitizer (-fsanitize=undefined plus subchecks)

Detects undefined behavior in C/C++:

Typical use: “catch UB that may not crash but is wrong.”

Purpose: Detects undefined behavior at runtime (language/ABI rules violations).

Typical findings (examples)

How it works

Caveats


leak LSan — LeakSanitizer (-fsanitize=leak or ASan leak detection)

Detects memory leaks (unfreed allocations that become unreachable at program end).

Typical use: “keep long-running services/tests from silently leaking.” Often used as part of ASan on Linux.

Purpose: Detects memory leaks (objects that are allocated but not reachable at program end).

Typical findings

How it works

Caveats