Sanitizers and Memory Debugging

AddressSanitizer, UBSan, ThreadSanitizer and MemorySanitizer — what each instruments, what it costs, and where each belongs in a CI pipeline. Includes Valgrind memcheck as the no-rebuild fallback and how to read a sanitizer report.

Overview

Delayed, misattributed failures

Memory bugs survive code review and unit tests, then crash in production with a stack nowhere near the fault. A heap overflow corrupts a neighbor and the failure surfaces later in unrelated code; a use-after-free reads recycled memory whose values look plausible until they do not. Without a sanitizer, that late crash in unrelated code is all you get. Sanitizers turn these into immediate, precise reports at the exact instruction that did the wrong thing.

Key concepts

  • Shadow memory
  • Redzone
  • Quarantine
  • Recoverable vs non-recoverable check
  • Instrumentation completeness
  • Suppressions vs ignorelist
  • LeakSanitizer
  • Origin tracking

Interview questions

  • Walk me through this AddressSanitizer report line by line. What is the bug, and what do the shadow bytes tell you?
  • Why can ASan and TSan not be combined, and how does that shape your CI matrix?
  • Your ASan and UBSan job has been green for six months, but a customer just hit a signed overflow bug in code that job exercises. What went wrong?
  • When would you use Valgrind memcheck instead of a sanitizer, and what does it cost you?
  • How does ASan actually detect a heap buffer overflow, and what classes of memory bug does it structurally miss?

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio