# ptmalloc

## What is ptmalloc2

**ptmalloc2** is the dynamic memory allocator used by glibc since version 2.3.x. It is a fork of the original malloc with improved multi-threading support. It is also very fast (6 times faster) compared to the original malloc. Specifically, we are interested in the implementation of `malloc.c`. The very first step of getting into heap exploitation is reading `malloc.c` and understanding its algorithms.

## Setup

Download and extract the latest glibc (the current version is 2.35):

```bash
cd /usr/src/glibc
sudo wget http://mirror.ibcp.fr/pub/gnu/libc/glibc-2.35.tar.xz
sudo tar xf glibc-2.35.tar.xz
```

The `malloc.c` file can be found at `/usr/src/glibc/glibc-2.35/malloc`.

## Reference

{% embed url="<https://ctf-wiki.org/pwn/linux/user-mode/heap/ptmalloc2/heap-overview>" %}
Heap - CTF Wiki
{% endembed %}
