fix(napi): arraybuffer memory leak (#1420)
This commit is contained in:
parent
44eb4c6341
commit
ce2a29fca7
3 changed files with 9 additions and 0 deletions
|
@ -125,6 +125,7 @@ macro_rules! impl_typed_array {
|
|||
fn noop_finalize(_data: *mut $rust_type, _length: usize) {}
|
||||
|
||||
pub fn new(mut data: Vec<$rust_type>) -> Self {
|
||||
data.shrink_to_fit();
|
||||
let ret = $name {
|
||||
data: data.as_mut_ptr(),
|
||||
length: data.len(),
|
||||
|
|
|
@ -17,6 +17,7 @@ while (true) {
|
|||
api.arrayBufferLen()
|
||||
api.bufferConvert(Buffer.from(FIXTURE))
|
||||
api.arrayBufferConvert(Uint8Array.from(FIXTURE))
|
||||
api.arrayBufferCreateFromVecWithSpareCapacity()
|
||||
api.bufferPassThrough(Buffer.from(FIXTURE))
|
||||
api.arrayBufferPassThrough(Uint8Array.from(FIXTURE))
|
||||
if (i % 10 === 0) {
|
||||
|
|
|
@ -157,6 +157,13 @@ pub fn array_buffer_convert(array_buffer: Uint8Array) -> Uint8Array {
|
|||
Uint8Array::new(vec![1; array_buffer.len()])
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn array_buffer_create_from_vec_with_spare_capacity() -> Uint8Array {
|
||||
let mut v = vec![1; 1024 * 10240];
|
||||
v.truncate(1);
|
||||
Uint8Array::new(v)
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn array_buffer_len() -> u32 {
|
||||
Uint8Array::new(vec![1; 1024 * 10240]).len() as u32
|
||||
|
|
Loading…
Reference in a new issue