Bug 1624529 - Add null-check before Box::from_raw. r=nbp
authorTooru Fujisawa <arai_a@mac.com>
Tue, 24 Mar 2020 10:31:07 +0000
changeset 520199 b9862f5a69d44db8f06c2aae3f351227320d2840
parent 520198 7c5e444f33509c83e7db02fcee987680f0edcbed
child 520200 88126ed3e7603cf446b4af93c0fa1743af4cb75a
push id37245
push useropoprus@mozilla.com
push dateTue, 24 Mar 2020 21:46:41 +0000
treeherdermozilla-central@dbabf2e388fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1624529
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1624529 - Add null-check before Box::from_raw. r=nbp Differential Revision: https://phabricator.services.mozilla.com/D68002
js/src/frontend/smoosh/src/lib.rs
--- a/js/src/frontend/smoosh/src/lib.rs
+++ b/js/src/frontend/smoosh/src/lib.rs
@@ -437,18 +437,22 @@ pub unsafe extern "C" fn free_smoosh(res
     let _ = result.error.into();
     let _ = result.bytecode.into();
     let _ = result.atoms.into();
     let _ = result.gcthings.into();
     let _ = result.scopes.into();
     let _ = result.scope_notes.into();
     //Vec::from_raw_parts(bytecode.data, bytecode.len, bytecode.capacity);
 
-    let _ = Box::from_raw(result.all_atoms as *mut Vec<&str>);
-    let _ = Box::from_raw(result.allocator as *mut bumpalo::Bump);
+    if !result.all_atoms.is_null() {
+        let _ = Box::from_raw(result.all_atoms as *mut Vec<&str>);
+    }
+    if !result.allocator.is_null() {
+        let _ = Box::from_raw(result.allocator as *mut bumpalo::Bump);
+    }
 }
 
 fn smoosh<'alloc>(
     allocator: &'alloc bumpalo::Bump,
     text: &'alloc str,
     options: &SmooshCompileOptions,
 ) -> Result<EmitResult<'alloc>, SmooshError> {
     let parse_options = ParseOptions::new();