Skip to content

alloc_system: Handle failure properly - #32997

Merged
bors merged 1 commit into
rust-lang:masterfrom
alexcrichton:fix-alloc-system-how-did-this-land
Apr 16, 2016
Merged

alloc_system: Handle failure properly#32997
bors merged 1 commit into
rust-lang:masterfrom
alexcrichton:fix-alloc-system-how-did-this-land

Conversation

@alexcrichton

Copy link
Copy Markdown
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.
Closesrust-lang#32993
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @aturon

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

@alexcrichton

Copy link
Copy Markdown
MemberAuthor

r? @brson

@rust-highfiverust-highfive assigned brson and unassigned aturonApr 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
Copy Markdown
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.

@nagisanagisaApr 15, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

r=me with comment fixed.

@nagisa

Copy link
Copy Markdown
Member

@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.
Closesrust-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:masterApr 16, 2016
@alexcrichton
alexcrichton deleted the fix-alloc-system-how-did-this-land branch May 2, 2016 18:44
Sign up for freeto 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.

6 participants

@alexcrichton@rust-highfive@nagisa@brson@aturon@bors