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

Patch memory release #23

Closed
wants to merge 1 commit into from
Closed

Patch memory release #23

wants to merge 1 commit into from

Conversation

fysu
Copy link

@fysu fysu commented Sep 17, 2022

这里需要判读下是否是要被释放的块,因为当前块要被释放了,作者没有清理,导致下次分配内存的时候就会出现问题,这里看下我的修复

@LessComplexity
Copy link
Member

LessComplexity commented Oct 24, 2022

@fysu

这里需要判读下是否是要被释放的块,因为当前块要被释放了,作者没有清理,导致下次分配内存的时候就会出现问题,这里看下我的修复

Thank you for the fix, your fix is still not correct but it addresses a real issue, the correct fix for it is to change the first 2 conditions:

// Case of the first block
if (block == this->firstBlock) {
	this->firstBlock = block->next;
	this->firstBlock->prev = nullptr;
}
// Case of the last block
else if (block == this->currentBlock) {
	this->currentBlock = block->prev;
	this->currentBlock->next = nullptr;
}

The reason your proposed fix poses a problem can be seen for the first case:

if (this->firstBlock->next == block) {
	this->firstBlock->next = 0;
}

What if block is between firstBlock and currentBlock? then the first block will not be linked to the last block and it will cause a problem when freeing the pool. Same goes for the condition:

if (this->currentBlock->prev == block) {
	this->currentBlock->prev = 0;
}

The other conditions are correct and they solve the problem, I just "integrated" them into the first 2 conditions that are already present.

Thank you very much! :)

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

Successfully merging this pull request may close these issues.

2 participants