-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
alloc_system: Handle failure properly #32997
alloc_system: Handle failure properly #32997
Conversation
The Unix implementation was incorrectly handling failure for reallocation of over-aligned types by not checking for NULL. Closes rust-lang#32993
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
r? @brson |
deallocate(ptr, old_size, align); | ||
if !new_ptr.is_null() { | ||
ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); | ||
deallocate(ptr, old_size, align); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should deallocate
this memory despite of failure in allocating new_ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, never mind me.
The manual for realloc
says:
If the area pointed to was moved, a free(ptr) is done.
and
If realloc() fails, the original block is left untouched; it is not freed or moved.
So it is required for memory to not get freed if move fails.
r=me with comment fixed. |
…id-this-land, r=nagisa alloc_system: Handle failure properly The Unix implementation was incorrectly handling failure for reallocation of over-aligned types by not checking for NULL. Closes rust-lang#32993
The Unix implementation was incorrectly handling failure for reallocation of
over-aligned types by not checking for NULL.
Closes #32993