diff --git a/crates/neon-runtime/src/napi/bindings/functions.rs b/crates/neon-runtime/src/napi/bindings/functions.rs index df57ab7c8..b8d29b16e 100644 --- a/crates/neon-runtime/src/napi/bindings/functions.rs +++ b/crates/neon-runtime/src/napi/bindings/functions.rs @@ -173,6 +173,8 @@ mod napi1 { fn reference_unref(env: Env, reference: Ref, result: *mut u32) -> Status; + fn delete_reference(env: Env, reference: Ref) -> Status; + fn get_reference_value(env: Env, reference: Ref, result: *mut Value) -> Status; fn strict_equals(env: Env, lhs: Value, rhs: Value, result: *mut bool) -> Status; diff --git a/crates/neon-runtime/src/napi/reference.rs b/crates/neon-runtime/src/napi/reference.rs index 9166fa3cb..ce144d615 100644 --- a/crates/neon-runtime/src/napi/reference.rs +++ b/crates/neon-runtime/src/napi/reference.rs @@ -26,7 +26,7 @@ pub unsafe fn reference(env: Env, value: napi::Ref) -> usize { result.assume_init() as usize } -pub unsafe fn unreference(env: Env, value: napi::Ref) -> usize { +pub unsafe fn unreference(env: Env, value: napi::Ref) { let mut result = MaybeUninit::uninit(); assert_eq!( @@ -34,7 +34,9 @@ pub unsafe fn unreference(env: Env, value: napi::Ref) -> usize { napi::Status::Ok, ); - result.assume_init() as usize + if result.assume_init() == 0 { + assert_eq!(napi::delete_reference(env, value), napi::Status::Ok); + } } pub unsafe fn get(env: Env, value: napi::Ref) -> Local {