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::dealloc is unsound #37

Open
nikitax44 opened this issue Oct 9, 2024 · 3 comments
Open

Heap::dealloc is unsound #37

nikitax44 opened this issue Oct 9, 2024 · 3 comments

Comments

@nikitax44
Copy link

it is possible to cause segfault in entirely safe code:

fn main() {
    let mut heap = buddy_system_allocator::Heap<10>::new();
    heap.dealloc(
        std::ptr::NonNull::dangling(),
        std::alloc::Layout::from_size_align(1, 1).unwrap(),
    );
}
@jiegec
Copy link
Member

jiegec commented Oct 10, 2024

Yes, but as this is an allocator, we don't want to support such case, since the expected usage is via global_allocator.

@nikitax44
Copy link
Author

this function should be unsafe. you shouldn't expose safe functions that may cause UB. the unsafe attribute does not conflict with global allocator use case as GlobalAlloc::dealloc is declared to be unsafe.

@jiegec
Copy link
Member

jiegec commented Oct 10, 2024

this function should be unsafe. you shouldn't expose safe functions that may cause UB. the unsafe attribute does not conflict with global allocator use case as GlobalAlloc::dealloc is declared to be unsafe.

Okay, please add the unsafe attribute in a pull request.

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

2 participants