Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heap.c中split_chunk()函数中指针操作的疑问 #26

Open
nekopara-orz opened this issue Aug 22, 2020 · 2 comments
Open

heap.c中split_chunk()函数中指针操作的疑问 #26

nekopara-orz opened this issue Aug 22, 2020 · 2 comments

Comments

@nekopara-orz
Copy link

split_chunk()函数缺少了
next_chunck->next->prev = next_chunck;
如果不这样的话 newchunk->next->pre永远指向 chunk 而不是 newchunk。
是否应该添加这样的代码

if(newchunck->next) {
    newchunck->next->prev = newchunck;
}
@ghost
Copy link

ghost commented Aug 24, 2020

newchunk->next->pre并没有指向chunk,而是默认值NULL,只有已经被申请的内存块的pre指针才有意义(:smile:我瞎猜的,欢迎大佬批评指正

@nekopara-orz
Copy link
Author

newchunk->next->pre并没有指向chunk,而是默认值NULL,只有已经被申请的内存块的pre指针才有意义(😄我瞎猜的,欢迎大佬批评指正

1->2
考虑这样一种情况,在某次分配、合并结束后有上面这两块内存,1号没被分配2号被分配了这时候2指向1。

1->3->2

这时候我又从1中分配了了一块内存这时候newchunk就是3,3的next->pre如果不更改的话就会还指向1也就是2的pre还是1不是3。
那么如果3被分配出去了。1和2回收时不管3回收没都会被glue函数回收掉。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant