fix(napi): memory issue while creating external buffer on electron

This commit is contained in:
LongYinan 2024-01-26 11:59:30 +08:00
parent aff95d0271
commit b9ba7c9d68
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 3 additions and 3 deletions

View file

@ -405,7 +405,7 @@ macro_rules! impl_typed_array {
&mut arraybuffer_value,
)
};
unsafe { std::ptr::copy(hint.data.cast(), underlying_data, length) };
unsafe { std::ptr::copy_nonoverlapping(hint.data.cast(), underlying_data, length) };
status
} else {
status

View file

@ -461,7 +461,7 @@ impl Env {
let mut underlying_data = ptr::null_mut();
let status =
sys::napi_create_arraybuffer(self.0, length, &mut underlying_data, &mut raw_value);
ptr::swap(underlying_data.cast(), data_ptr);
ptr::copy_nonoverlapping(underlying_data.cast(), data_ptr, length);
status
} else {
status
@ -476,7 +476,7 @@ impl Env {
value: raw_value,
value_type: ValueType::Object,
}),
data_ptr as *mut c_void,
data_ptr.cast(),
length,
))
}