diff options
author | Julian Seward <jseward@acm.org> | 2017-10-02 20:53:23 +0200 |
---|---|---|
committer | Julian Seward <jseward@acm.org> | 2017-10-02 20:53:23 +0200 |
commit | 419642a2bd7b15ad8b6e8bbe68a8dd6f9e778174 (patch) | |
tree | 3157b084fec611755476690600908fe65fbb1d59 /components/fallible | |
parent | e13f5a656af682add10cdc41fb8e625c04b60347 (diff) | |
download | servo-419642a2bd7b15ad8b6e8bbe68a8dd6f9e778174.tar.gz servo-419642a2bd7b15ad8b6e8bbe68a8dd6f9e778174.zip |
Bug 1400754 - stylo: crash on Win64 Asan build. r=manishearth, dmajor.
* adds a hashglobe::alloc::realloc, as that was previously not implemented,
copying and simplifying from liballoc_system.
* routes malloc and realloc calls through hashglobe::alloc::, instead of
doing it via direct 'extern "C"' calls.
Diffstat (limited to 'components/fallible')
-rw-r--r-- | components/fallible/lib.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/components/fallible/lib.rs b/components/fallible/lib.rs index 4a48190a1eb..c220699a786 100644 --- a/components/fallible/lib.rs +++ b/components/fallible/lib.rs @@ -6,16 +6,12 @@ extern crate hashglobe; extern crate smallvec; use hashglobe::FailedAllocationError; +#[cfg(feature = "known_system_malloc")] +use hashglobe::alloc; use smallvec::Array; use smallvec::SmallVec; use std::vec::Vec; -#[cfg(feature = "known_system_malloc")] -extern "C" { - fn realloc(ptr: *mut u8, bytes: usize) -> *mut u8; - fn malloc(bytes: usize) -> *mut u8; -} - pub trait FallibleVec<T> { /// Append |val| to the end of |vec|. Returns Ok(()) on success, /// Err(reason) if it fails, with |reason| describing the failure. @@ -67,9 +63,9 @@ fn try_double_vec<T>(vec: &mut Vec<T>) -> Result<(), FailedAllocationError> { let new_ptr = unsafe { if old_cap == 0 { - malloc(new_size_bytes) + alloc::alloc(new_size_bytes, 0) } else { - realloc(old_ptr as *mut u8, new_size_bytes) + alloc::realloc(old_ptr as *mut u8, new_size_bytes) } }; @@ -146,12 +142,12 @@ where // There's an old block to free, and, presumably, old contents to // copy. realloc takes care of both aspects. unsafe { - new_ptr = realloc(old_ptr as *mut u8, new_size_bytes); + new_ptr = alloc::realloc(old_ptr as *mut u8, new_size_bytes); } } else { // There's no old block to free. There may be old contents to copy. unsafe { - new_ptr = malloc(new_size_bytes); + new_ptr = alloc::alloc(new_size_bytes, 0); if !new_ptr.is_null() && old_size_bytes > 0 { copy_nonoverlapping(old_ptr as *const u8, new_ptr as *mut u8, old_size_bytes); |