diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-04-15 10:02:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-04-15 10:02:21 -0700 |
| commit | 99c05478542c6624d537f587ce34f84d09fd0627 (patch) | |
| tree | 8df9b944a57b868bb47ec0f9bb8d20e5622d6e44 /src/liballoc_system | |
| parent | 74b3684d009c0e243a282c9a573ef5e29a2681d9 (diff) | |
| download | rust-99c05478542c6624d537f587ce34f84d09fd0627.tar.gz rust-99c05478542c6624d537f587ce34f84d09fd0627.zip | |
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 } } |
