Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing napi_delete_reference on ObjectWrap ref #1607

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Oct 31, 2024

According to https://nodejs.org/api/n-api.html#napi_wrap, the napi_reference returned from napi_wrap should be deleted with napi_delete_reference. In node-addon-api, for an ObjectWrap, this is done with ~Reference destructor when the _ref is not nullptr.

To prevent ~ObjectWrap from creating a handle during finalization, add a new flag to guard on it, instead of nullify _ref.

Submitted nodejs/node#55620 to allow napi_delete_reference been immediately invoked in an node_api_basic_finalizer.

Fixes #1602

@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.35%. Comparing base (19002d5) to head (4e05944).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1607      +/-   ##
==========================================
- Coverage   66.40%   66.35%   -0.05%     
==========================================
  Files           3        3              
  Lines        2143     2143              
  Branches      702      703       +1     
==========================================
- Hits         1423     1422       -1     
  Misses        150      150              
- Partials      570      571       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mhdawson mhdawson mentioned this pull request Nov 1, 2024
@legendecas legendecas merged commit 98aae33 into nodejs:main Nov 7, 2024
54 checks passed
@legendecas legendecas deleted the remove_wrap branch November 7, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

ObjectWrap leak introduced in 8.2.0
3 participants