From 7d9fab248547a95f680ea1e2f649beaba4aab8ae Mon Sep 17 00:00:00 2001 From: modeco80 Date: Fri, 23 Aug 2024 04:39:23 -0400 Subject: [PATCH] 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 --- cvm-rs/src/jpeg_js.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cvm-rs/src/jpeg_js.rs b/cvm-rs/src/jpeg_js.rs index 786db4a..6f1004c 100644 --- a/cvm-rs/src/jpeg_js.rs +++ b/cvm-rs/src/jpeg_js.rs @@ -46,8 +46,8 @@ pub struct JpegInputArgs { #[napi(js_name = "jpegEncode")] #[allow(unused)] pub fn jpeg_encode(env: Env, input: JpegInputArgs) -> napi::Result { - let (deferred_resolver, promise) = env.create_deferred::()?; - let buf = input.buffer.into_ref()?; + let (deferred_resolver, promise) = env.create_deferred::()?; + let mut buf = input.buffer.into_ref()?; // Spawn a task on the rayon pool that encodes the JPEG and fufills the promise // once it is done encoding. @@ -72,7 +72,9 @@ pub fn jpeg_encode(env: Env, input: JpegInputArgs) -> napi::Result