WCU / Cybersecurity
~/CSC 472/Class 09/KP 03
Class 09 · KP 03 / 25

glibc malloc (ptmalloc2): The Big Picture

  • Linux's default allocator is ptmalloc2, built into glibc. It hands out memory in units called chunks.
  • Requests are rounded up and carry inline metadata: each chunk stores its own size and, when free, pointers to other free chunks.
  • Freed chunks are not returned to the OS immediately; they are cached in bins (free lists) for fast reuse.
  • The arena is the top-level bookkeeping structure that owns these bins. The main thread uses the main arena; extra threads get their own arenas.
  • Design goal: speed. Reusing recently freed chunks is fast — but that reuse is exactly what attackers exploit.
Key Takeaway

malloc trades safety for speed by storing metadata inline and aggressively recycling freed chunks.