From 2820b7ac53f2fd9e31182e35733539a529d62a5a Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 7 Apr 2017 09:50:57 +1000 Subject: [PATCH] Move dummy url data to be a static member of URLExtraData. --- Cargo.lock | 2 -- ports/geckolib/glue.rs | 15 +++++++-------- tests/unit/stylo/Cargo.toml | 2 -- tests/unit/stylo/lib.rs | 2 -- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a7349176ad..065e1669a4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2787,12 +2787,10 @@ dependencies = [ "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "geckoservo 0.0.1", - "lazy_static 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.18.0", - "servo_url 0.0.1", "style 0.0.1", "style_traits 0.0.1", ] diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d43bc6306d8..94f03ebbb4e 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -100,10 +100,10 @@ use super::stylesheet_loader::StylesheetLoader; // A dummy url data for where we don't pass url data in. // We need to get rid of this sooner than later. -static mut DUMMY_URL_DATA: Option<*mut URLExtraData> = None; +static mut DUMMY_URL_DATA: *mut URLExtraData = 0 as *mut URLExtraData; #[no_mangle] -pub extern "C" fn Servo_Initialize() { +pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) { // Initialize logging. let mut builder = LogBuilder::new(); let default_level = if cfg!(debug_assertions) { "warn" } else { "error" }; @@ -122,9 +122,7 @@ pub extern "C" fn Servo_Initialize() { gecko_properties::initialize(); // Initialize the dummy url data - unsafe { - DUMMY_URL_DATA = Some(bindings::Gecko_URLExtraData_CreateDummy()); - } + unsafe { DUMMY_URL_DATA = dummy_url_data; } } #[no_mangle] @@ -132,12 +130,13 @@ pub extern "C" fn Servo_Shutdown() { // Clear some static data to avoid shutdown leaks. gecko_properties::shutdown(); - // Clear the dummy url data to avoid shutdown leaks. - unsafe { RefPtr::from_addrefed(DUMMY_URL_DATA.take().unwrap()) }; + // The dummy url will be released after shutdown, so clear the + // reference to avoid use-after-free. + unsafe { DUMMY_URL_DATA = ptr::null_mut(); } } unsafe fn dummy_url_data() -> &'static RefPtr { - RefPtr::from_ptr_ref(DUMMY_URL_DATA.as_ref().unwrap()) + RefPtr::from_ptr_ref(&DUMMY_URL_DATA) } fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard, diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml index a75692076d7..7d6e4a0b17f 100644 --- a/tests/unit/stylo/Cargo.toml +++ b/tests/unit/stylo/Cargo.toml @@ -19,12 +19,10 @@ atomic_refcell = "0.1" cssparser = "0.12" env_logger = "0.4" euclid = "0.11" -lazy_static = "0.2" libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} parking_lot = "0.3" selectors = {path = "../../../components/selectors"} -servo_url = {path = "../../../components/url"} style_traits = {path = "../../../components/style_traits"} geckoservo = {path = "../../../ports/geckolib"} style = {path = "../../../components/style", features = ["gecko"]} diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs index db5837028b7..76b54a45b7d 100644 --- a/tests/unit/stylo/lib.rs +++ b/tests/unit/stylo/lib.rs @@ -6,11 +6,9 @@ extern crate atomic_refcell; extern crate cssparser; extern crate env_logger; extern crate geckoservo; -#[macro_use] extern crate lazy_static; #[macro_use] extern crate log; extern crate parking_lot; extern crate selectors; -extern crate servo_url; #[macro_use] extern crate style; extern crate style_traits;