PTMALLOC2

malloc_chunk structure

struct malloc_chunk {
    INTERNAL_SIZE_T mchunk_prev_size;  /* Size of previous chunk (if free).  */
    INTERNAL_SIZE_T mchunk_size;       /* Size in bytes, including overhead. */
  
    struct malloc_chunk* fd;         /* double links -- used only if free. */
    struct malloc_chunk* bk;
  
    /* Only used for large blocks: pointer to next larger size.  */
    struct malloc_chunk* fd_nextsize; /* double links -- used only if free. */
    struct malloc_chunk* bk_nextsize;
};
	

mchunk_size lower three bits are A | M | P


Top Chunk

Top chunk (aka wilderness): represents the end of available memory and is not allocated. PREV_INUSE is always set. Top chunk can be enlarged using sbrk().


Bins

ptmalloc introduces bins to cache chunks of memory for improved performance. When a chunk is freed, a pointer to it is cached in these bins. Also reduces fragmentation.

Hooks

Until versions < 2.34, glibc included several hooks in the from of global variables, which if set, would be called instead of the original function:

Common attacks

Leaking Libc Address