Learn C Programming

Lesson 5 of 9 · Dynamic Memory

Module 14 · Dynamic Memory

Leaks, Double Free, and the Tools That Find Them

Free with an accountReading

Kenji's server answers every request correctly, and keeps 4 KB from each one forever. At a thousand requests a minute, that is 240,000 KB an hour, almost the 256,000 KB a Playground run may touch. After a day it is over 5 GB.

Checking what this lesson needs for you…

What is inside Leaks, Double Free, and the Tools That Find Them

  1. A leak: a block nobody can reach
  2. Two ways to lose a block
  3. Every block has one owner
  4. A double free: glibc stops the program
  5. A use after free: wrong numbers, and no crash
  6. Freeing what malloc never handed out
  7. AddressSanitizer and LeakSanitizer
  8. The analyzer: GCC checks the paths without running them
  9. Valgrind, on your own Linux machine
  10. Why the Playground cannot name a leak
  11. The leak checklist