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

Adds code and documentation to rectify potential memory leaks in LinkedListAllocator #1182

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

seewishnew
Copy link
Contributor

@seewishnew seewishnew commented Dec 28, 2022

I am not sure if this was a design decision to keep things simple for the sake of the blog post implementation of the LinkedListAllocator, but the current alloc_from_region method can fail to keep track of free unused heap areas that are created due to misalignment between the free region and the layout request.

In x86_64, this can only happen if the layout request was for an alignment of 16 bytes and the region happened to start in the middle of this alignment, at some address 16*n + 8. The current behavior would "leak" the 8 bytes between 16*n + 8 and 16*(n+1) and never attempt to reclaim those regions even upon deallocation.

It seemed simple enough to ensure that we leave enough room in the beginning for at least another ListNode, following a similar approach in the linked_list_allocator crate.

This PR also adds a pretty simple test case to ensure we are not "leaking" these excess bytes on either end.

@seewishnew seewishnew changed the title Adds code and documentation to rectify potential leaky headers in LinkedListAllocator Adds code and documentation to rectify potential memory leaks in LinkedListAllocator Dec 28, 2022
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.

None yet

1 participant