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

alloc_system: Handle failure properly #32997

Merged

Conversation

alexcrichton
Copy link
Member

The Unix implementation was incorrectly handling failure for reallocation of
over-aligned types by not checking for NULL.

Closes #32993

The Unix implementation was incorrectly handling failure for reallocation of
over-aligned types by not checking for NULL.

Closes rust-lang#32993
@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned aturon Apr 15, 2016
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);
Copy link
Member

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.

Copy link
Member

@nagisa nagisa Apr 15, 2016

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.

@nagisa
Copy link
Member

nagisa commented Apr 15, 2016

r=me with comment fixed.

@nagisa
Copy link
Member

nagisa commented Apr 15, 2016

@bors r+ 99c0547

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 15, 2016
…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
bors added a commit that referenced this pull request Apr 15, 2016
Rollup of 11 pull requests

- Successful merges: #32923, #32926, #32929, #32931, #32935, #32945, #32946, #32964, #32970, #32973, #32997
- Failed merges:
@bors bors merged commit 99c0547 into rust-lang:master Apr 16, 2016
@alexcrichton alexcrichton deleted the fix-alloc-system-how-did-this-land branch May 2, 2016 18:44
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

6 participants