在阅读[Linux 堆内存管理深入分析(下)](https://github.com/JnuSimba/LinuxSecNotes/blob/master/Linux%20系统底层知识/Linux%20堆内存管理深入分析%EF%BC%88下%EF%BC%89.md)的过程中,发现一处自相矛盾的地方: > 2.每个fast bin都是一个单链表(只使用fd指针)。为什么使用单链表呢?因为在fast bin中无论是添加还是移除fast chunk,都是对“链表头”进行操作,而不会对某个中间的fast chunk进行操作。更具体点就是LIFO(后入先出)算法:**添加操作(free内存)就是将新的fast chunk加入链表头**,删除操作(malloc内存)就是将链表头部的fast chunk删除。 > 6. free(fast chunk)操作:这个操作很简单,主要分为两步:先通过chunksize函数根据传入的地址指针获取该指针对应的chunk的大小;然后根据这个chunk大小获取该chunk所属的fast bin,**然后再将此chunk添加到该fast bin的链尾即可**。整个操作都是在_int_free函数中完成。 在[Understanding glibc malloc](https://sploitfun.wordpress.com/2015/02/10/understanding-glibc-malloc/comment-page-1/)一文中: > - free(fast chunk) > - Fast bin index is calculated to retrieve its corresponding binlist. > - This free chunk gets added **at the front position of the above retrieved binlist**. 参考了源码[`_int_free`](https://github.com/sploitfun/lsploits/blob/master/glibc/malloc/malloc.c#L3893),看得不是完全地明白,像是插在了链尾。
Activity