From f792feba0bdb6ecb8ed7294111ca598e5551bb09 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 27 May 2021 20:18:02 +0800 Subject: [PATCH] fix(napi): wrong memory location of data in future resolved callback --- napi/src/promise.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/napi/src/promise.rs b/napi/src/promise.rs index cd32f739..e7f71439 100644 --- a/napi/src/promise.rs +++ b/napi/src/promise.rs @@ -58,7 +58,7 @@ impl FuturePromise { 1, ptr::null_mut(), None, - self_ref as *mut _ as *mut c_void, + self_ref as *mut FuturePromise as *mut c_void, Some(call_js_cb::), &mut tsfn_value, ) @@ -81,7 +81,7 @@ pub(crate) async fn resolve_from_future>>( check_status!(unsafe { sys::napi_call_threadsafe_function( tsfn_value.0, - Box::into_raw(Box::from(val)) as *mut _ as *mut c_void, + Box::into_raw(Box::from(val)) as *mut T as *mut c_void, sys::napi_threadsafe_function_call_mode::napi_tsfn_nonblocking, ) }) @@ -103,7 +103,7 @@ unsafe extern "C" fn call_js_cb( ) { let mut env = Env::from_raw(raw_env); let future_promise = Box::from_raw(context as *mut FuturePromise); - let value: Result = ptr::read(data as *const _); + let value = Box::from_raw(data as *mut Result); let resolver = future_promise.resolver; let deferred = future_promise.deferred; let js_value_to_resolve = value.and_then(move |v| (resolver)(&mut env, v));