about summary refs log tree commit diff
path: root/src/liballoc_system
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-04-15 10:02:21 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-04-15 10:02:21 -0700
commit99c05478542c6624d537f587ce34f84d09fd0627 (patch)
tree8df9b944a57b868bb47ec0f9bb8d20e5622d6e44 /src/liballoc_system
parent74b3684d009c0e243a282c9a573ef5e29a2681d9 (diff)
downloadrust-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.rs6
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
         }
     }