Repository navigation
fix(napi): cleanup memory issues - #2949
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
cursor review |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes memory management issues in the NAPI bindings by correcting improper memory handling patterns that could lead to memory leaks or undefined behavior.
- Replaces
CString::from_raw()withCStr::from_ptr()to avoid taking ownership of C strings - Moves heap allocation of hint pointer inside the conditional block where it's actually used
- Fixes String reconstruction to use the original capacity instead of length
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/napi/src/error.rs | Updates error message handling to avoid taking ownership of C strings |
| crates/napi/src/env.rs | Moves hint pointer allocation to prevent memory leak when not used |
| crates/napi/src/bindgen_runtime/js_values/arraybuffer.rs | Fixes String reconstruction to use correct capacity parameter |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
29d05a7 to
432b4de
Compare
432b4de to
7681cb9
Compare
e9fb176 to
0b68580
Compare
8b535dd to
a009c94
Compare
e715656 to
a3c42e3
Compare
a3c42e3 to
da66640
Compare
2306ef5 to
668c3b0
Compare
4a1bfbf to
8cf17c5
Compare

Note
Fixes buffer ownership/capacity and error-string retrieval to prevent leaks and undefined behavior.
js_values/arraybuffer.rs):Uint8Array::from_stringnow restoresStringwith originalcapacity(notlen) when finalizing.env.rs):create_buffer_with_datacreates the external buffer hint only for non-empty buffers (avoids unnecessary alloc on empty case).error.rs):CStr::from_ptr(...).to_str()?.to_owned()instead ofCString::from_rawto readnapi_extended_error_info.error_messagewithout taking ownership.Written by Cursor Bugbot for commit 96eaba5. This will update automatically on new commits. Configure here.