Skip to content

Commit

Permalink
fix(neon-runtime): Fix a leak from references not being deleted
Browse files Browse the repository at this point in the history
Fixes #746
  • Loading branch information
kjvalencik committed Jun 1, 2021
1 parent dd0af64 commit 8b26072
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/neon-runtime/src/napi/bindings/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions crates/neon-runtime/src/napi/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ 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!(
napi::reference_unref(env, value, result.as_mut_ptr()),
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 {
Expand Down

0 comments on commit 8b26072

Please sign in to comment.