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

Avoid memory leak #1265

Merged
merged 3 commits into from
Dec 4, 2018
Merged

Avoid memory leak #1265

merged 3 commits into from
Dec 4, 2018

Conversation

F001
Copy link
Contributor

@F001 F001 commented Dec 3, 2018

Fix #1263

It is hard to achieve zero-copy when passing message between Rust and C, because we can't assume they use the same allocator. There is only one case that zero-copy is easy:

1. Create buffer in Rust
2. Call function in C
    1. Pass borrowed pointer to C
    2. C only need to use this buffer in a limited time span
3.  The buffer is destroyed in Rust

I think deno is not as simple as this. Zero-copy will cost significant API complexity.

@@ -190,15 +190,12 @@ impl Isolate {

pub fn respond(&mut self, req_id: i32, buf: Buf) {
self.state.metrics_op_completed(buf.len());

// TODO(zero-copy) Use Buf::leak(buf) to leak the heap allocated buf. And
// don't do the memcpy in ImportBuf() (in libdeno/binding.cc)
Copy link
Member

Choose a reason for hiding this comment

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

Looks good - this solves the leak! I think there should be a comment here explaining that memcpy is used.

// deno_respond will memcpy the buf into V8's heap, so borrowing a reference here is sufficient. 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. The comment is added.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

@ry ry merged commit 9e839b7 into denoland:master Dec 4, 2018
ry added a commit to ry/deno that referenced this pull request Dec 7, 2018
- Don't crash when .mime file not exist in cache (denoland#1291)
- Process source maps in Rust instead of JS (denoland#1280)
- Use alternate TextEncoder/TextDecoder implementation (denoland#1281)
- Upgrade flatbuffers to 80d148
- Fix memory leaks (denoland#1265, denoland#1275)
@ry ry mentioned this pull request Dec 7, 2018
ry added a commit that referenced this pull request Dec 7, 2018
- Don't crash when .mime file not exist in cache (#1291)
- Process source maps in Rust instead of JS (#1280)
- Use alternate TextEncoder/TextDecoder implementation (#1281)
- Upgrade flatbuffers to 80d148
- Fix memory leaks (#1265, #1275)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants