From f3dcef8c8176ba3d76f0816cbbcb43eb8a58fdd9 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 5 Apr 2017 16:54:51 +0800 Subject: [PATCH 1/2] style: Add an Atom::from_addrefed function. --- components/style/gecko_string_cache/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 1c44df4eb17..587c2329d96 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -198,6 +198,16 @@ impl Atom { "Called from_static for a non-static atom!"); atom } + + /// Creates an atom from a dynamic atom pointer that has already had AddRef + /// called on it. + #[inline] + pub unsafe fn from_addrefed(ptr: *mut nsIAtom) -> Self { + debug_assert!(!ptr.is_null()); + unsafe { + Atom(WeakAtom::new(ptr)) + } + } } impl Hash for Atom { From 581cefccfebdfa285e0b22c9688853a35d91f14c Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 5 Apr 2017 16:58:39 +0800 Subject: [PATCH 2/2] stylo: Don't leak the nsIAtom we get back from Gecko_GetXMLLangValue. --- components/style/gecko/wrapper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 9ec7ee3cf76..6f59864b322 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -694,7 +694,7 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> { let global_style_data = &*GLOBAL_STYLE_DATA; let pdb = PropertyDeclarationBlock::with_one( - PropertyDeclaration::XLang(SpecifiedLang(Atom::from(ptr))), + PropertyDeclaration::XLang(SpecifiedLang(unsafe { Atom::from_addrefed(ptr) })), Importance::Normal ); let arc = Arc::new(global_style_data.shared_lock.wrap(pdb));