malloc: glibc and musl
heap.c:9 free(b);
kernel
memory
cpu
source
glibc 2.39
ptmalloc
the heap: one run of chunks
a
b
c
tcache
unused
32 bytes
inside b
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
1
size
of this chunk
0
0
0
0
0
0
0
5
5
d
4
a
1
c
0
3
next
free chunk: none
8
f
3
a
6
1
c
2
d
0
7
b
4
e
1
9
key
marks it freed
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
a
your old data
0x20
1 free
0x30
0
0x40
0
0x50
0
0x60
0
0x70
0
its notes: a list for each size, kept in the heap itself
musl 1.2.5
mallocng
the heap: groups of equal slots
c
112-byte slots
a
b
32-byte slots
inside b
f
f
0
0
0
0
0
0
its tag, cleared
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
a
your old data,
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
all of it untouched
can hand out
0
0
1
1
1
1
1
1
1
1
freed
0
1
0
0
0
0
0
0
0
0
a
b
one bit for each slot
its notes: one record for each group, kept apart
glibc threads its free list through the freed chunk itself.
musl flips one bit in a record it keeps apart from your data.