mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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.
This commit is contained in:
parent
e13f5a656a
commit
419642a2bd
3 changed files with 22 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue