diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-16 01:16:45 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-16 01:18:14 +0530 |
| commit | e563359396928453db81141bf12dae04a567f2e9 (patch) | |
| tree | 1ed06a5b72b212d39c38d2607f9631bb466c17b1 /src/liballoc_system | |
| parent | eba80558d7223900549786207fad4791e1f01d88 (diff) | |
| parent | 99c05478542c6624d537f587ce34f84d09fd0627 (diff) | |
| download | rust-e563359396928453db81141bf12dae04a567f2e9.tar.gz rust-e563359396928453db81141bf12dae04a567f2e9.zip | |
Rollup merge of #32997 - alexcrichton:fix-alloc-system-how-did-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 #32993
Diffstat (limited to 'src/liballoc_system')
| -rw-r--r-- | src/liballoc_system/lib.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 6a62e00d311..ca4c9bfd954 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -96,8 +96,10 @@ mod imp { libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 } else { let new_ptr = allocate(size, align); - ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); - 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); + } new_ptr } } |
