From e4f005c7350beb5faf1c4a42d8c9d01b69f3d3d6 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 15 Nov 2020 23:22:29 +0800 Subject: [PATCH] fix(napi): memory leak with CString --- napi/src/env.rs | 2 +- napi/src/js_values/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/napi/src/env.rs b/napi/src/env.rs index 666fdf76..462744b9 100644 --- a/napi/src/env.rs +++ b/napi/src/env.rs @@ -349,7 +349,7 @@ impl Env { check_status(unsafe { sys::napi_create_function( self.0, - name.into_raw(), + name.as_ptr(), len, Some(callback), ptr::null_mut(), diff --git a/napi/src/js_values/mod.rs b/napi/src/js_values/mod.rs index 4c212c41..65387f5f 100644 --- a/napi/src/js_values/mod.rs +++ b/napi/src/js_values/mod.rs @@ -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.into_raw(), &mut raw_value) + sys::napi_get_named_property(self.0.env, self.0.value, key.as_ptr(), &mut raw_value) })?; T::from_raw(self.0.env, raw_value) }