fix(napi): CString memory leak

This commit is contained in:
LongYinan 2020-11-20 09:13:25 +08:00
parent e337a58714
commit c370b8374b
No known key found for this signature in database
GPG key ID: A3FFE134A3E20881
3 changed files with 3 additions and 5 deletions

View file

@ -204,7 +204,7 @@ fn get_execute_js_code(
Err(e) => { Err(e) => {
let message = format!("{}", e); let message = format!("{}", e);
unsafe { unsafe {
napi::sys::napi_throw_error(raw_env, ptr::null(), CString::from_vec_unchecked(message.into()).into_raw()); napi::sys::napi_throw_error(raw_env, ptr::null(), CString::from_vec_unchecked(message.into()).as_ptr());
} }
ptr::null_mut() ptr::null_mut()
} }

View file

@ -367,9 +367,7 @@ impl Env {
} }
pub fn throw_error(&self, msg: &str) -> Result<()> { pub fn throw_error(&self, msg: &str) -> Result<()> {
check_status(unsafe { check_status(unsafe { sys::napi_throw_error(self.0, ptr::null(), CString::new(msg)?.as_ptr()) })
sys::napi_throw_error(self.0, ptr::null(), CString::new(msg)?.into_raw())
})
} }
pub fn define_class( pub fn define_class(

View file

@ -188,7 +188,7 @@ macro_rules! register_module {
raw_env, raw_env,
ptr::null(), ptr::null(),
CString::from_vec_unchecked(format!("Error initializing module: {}", e).into()) CString::from_vec_unchecked(format!("Error initializing module: {}", e).into())
.into_raw() as *const _, .as_ptr(),
) )
}; };
ptr::null_mut() ptr::null_mut()