提交 9e839b7e 编写于 作者: F F001 提交者: Ryan Dahl

Avoid memory leak (#1265)

上级 f6c841a6
......@@ -190,15 +190,14 @@ 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)
// deno_respond will memcpy the buf into V8's heap,
// so borrowing a reference here is sufficient.
unsafe {
libdeno::deno_respond(
self.libdeno_isolate,
self.as_void_ptr(),
req_id,
buf.into(),
buf.as_ref().into(),
)
}
}
......@@ -271,20 +270,6 @@ impl Drop for Isolate {
}
}
/// Converts Rust Buf to libdeno `deno_buf`.
impl From<Buf> for libdeno::deno_buf {
fn from(x: Buf) -> Self {
let len = x.len();
let ptr = Box::into_raw(x);
Self {
alloc_ptr: std::ptr::null_mut(),
alloc_len: 0,
data_ptr: ptr as *mut u8,
data_len: len,
}
}
}
// Dereferences the C pointer into the Rust Isolate object.
extern "C" fn pre_dispatch(
user_data: *mut c_void,
......
......@@ -29,6 +29,18 @@ impl deno_buf {
}
}
/// Converts Rust &Buf to libdeno `deno_buf`.
impl<'a> From<&'a [u8]> for deno_buf {
fn from(x: &'a [u8]) -> Self {
Self {
alloc_ptr: std::ptr::null_mut(),
alloc_len: 0,
data_ptr: x.as_ref().as_ptr() as *mut u8,
data_len: x.len(),
}
}
}
type DenoRecvCb = unsafe extern "C" fn(
user_data: *mut c_void,
req_id: i32,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册