mirror of
https://github.com/computernewb/collabvm-1.2.ts.git
synced 2025-01-22 10:42:00 -05:00
cvm-rs: don't leave reference to input buffer live
i think this was causing it to not be freed because we were holding a live reference (to NAPI/node/v8 side of things) even after we were done so the input buffer just never got freed from the buffer pool
This commit is contained in:
parent
17191b0917
commit
7d9fab2485
1 changed files with 5 additions and 3 deletions
|
@ -46,8 +46,8 @@ pub struct JpegInputArgs {
|
||||||
#[napi(js_name = "jpegEncode")]
|
#[napi(js_name = "jpegEncode")]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn jpeg_encode(env: Env, input: JpegInputArgs) -> napi::Result<napi::JsObject> {
|
pub fn jpeg_encode(env: Env, input: JpegInputArgs) -> napi::Result<napi::JsObject> {
|
||||||
let (deferred_resolver, promise) = env.create_deferred::<napi::JsUnknown, _>()?;
|
let (deferred_resolver, promise) = env.create_deferred::<napi::JsBuffer, _>()?;
|
||||||
let buf = input.buffer.into_ref()?;
|
let mut buf = input.buffer.into_ref()?;
|
||||||
|
|
||||||
// Spawn a task on the rayon pool that encodes the JPEG and fufills the promise
|
// Spawn a task on the rayon pool that encodes the JPEG and fufills the promise
|
||||||
// once it is done encoding.
|
// once it is done encoding.
|
||||||
|
@ -72,7 +72,9 @@ pub fn jpeg_encode(env: Env, input: JpegInputArgs) -> napi::Result<napi::JsObjec
|
||||||
let buffer = env
|
let buffer = env
|
||||||
.create_buffer_with_data(vec)
|
.create_buffer_with_data(vec)
|
||||||
.expect("Couldn't create node Buffer, things are probably very broken by this point");
|
.expect("Couldn't create node Buffer, things are probably very broken by this point");
|
||||||
Ok(buffer.into_unknown())
|
// no longer need the input buffer
|
||||||
|
buf.unref(env)?;
|
||||||
|
Ok(buffer.into_raw())
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue