fix(napi): memory leak in create_named_property

This commit is contained in:
LongYinan 2020-11-14 11:45:10 +08:00
parent 4609fae1cb
commit 68017ce246
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
3 changed files with 3 additions and 3 deletions

View file

@ -43,7 +43,7 @@ version = "0.3"
[dependencies.once_cell]
optional = true
version = "1.4"
version = "1.5"
[dependencies.serde]
optional = true

View file

@ -344,7 +344,7 @@ impl Env {
pub fn create_function(&self, name: &str, callback: Callback) -> Result<JsFunction> {
let mut raw_result = ptr::null_mut();
let name = CString::new(name.to_owned())?;
let name = CString::new(name)?;
let len = name.as_bytes().len();
check_status(unsafe {
sys::napi_create_function(

View file

@ -269,7 +269,7 @@ macro_rules! impl_object_methods {
let key = CString::new(name)?;
let mut raw_value = ptr::null_mut();
check_status(unsafe {
sys::napi_get_named_property(self.0.env, self.0.value, key.as_ptr(), &mut raw_value)
sys::napi_get_named_property(self.0.env, self.0.value, key.into_raw(), &mut raw_value)
})?;
T::from_raw(self.0.env, raw_value)
}