mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
stream_wrap: add HandleScope's in uv callbacks
Ensure that no handles will leak into global HandleScope by adding HandleScope's in all JS-calling libuv callbacks in `stream_wrap.cc`. Fix: https://github.com/iojs/io.js/issues/1075 PR-URL: https://github.com/iojs/io.js/pull/1078 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
b27931b0fe
commit
583a868bcd
2 files changed
+8
-14
No files matched your search
@@ -145,6 +145,9 @@ void StreamWrap::OnAlloc(uv_handle_t* handle,
|
|||||||
size_t suggested_size,
|
size_t suggested_size,
|
||||||
uv_buf_t* buf) {
|
uv_buf_t* buf) {
|
||||||
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
|
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
|
||||||
|
HandleScope scope(wrap->env()->isolate());
|
||||||
|
Context::Scope context_scope(wrap->env()->context());
|
||||||
|
|
||||||
CHECK_EQ(wrap->stream(), reinterpret_cast<uv_stream_t*>(handle));
|
CHECK_EQ(wrap->stream(), reinterpret_cast<uv_stream_t*>(handle));
|
||||||
|
|
||||||
return static_cast<StreamBase*>(wrap)->OnAlloc(suggested_size, buf);
|
return static_cast<StreamBase*>(wrap)->OnAlloc(suggested_size, buf);
|
||||||
@@ -229,6 +232,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle,
|
|||||||
const uv_buf_t* buf,
|
const uv_buf_t* buf,
|
||||||
uv_handle_type pending) {
|
uv_handle_type pending) {
|
||||||
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
|
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
|
||||||
|
HandleScope scope(wrap->env()->isolate());
|
||||||
|
|
||||||
// We should not be getting this callback if someone as already called
|
// We should not be getting this callback if someone as already called
|
||||||
// uv_close() on the handle.
|
// uv_close() on the handle.
|
||||||
@@ -280,6 +284,8 @@ int StreamWrap::DoShutdown(ShutdownWrap* req_wrap) {
|
|||||||
|
|
||||||
void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
|
void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
|
||||||
ShutdownWrap* req_wrap = ContainerOf(&ShutdownWrap::req_, req);
|
ShutdownWrap* req_wrap = ContainerOf(&ShutdownWrap::req_, req);
|
||||||
|
HandleScope scope(req_wrap->env()->isolate());
|
||||||
|
Context::Scope context_scope(req_wrap->env()->context());
|
||||||
req_wrap->Done(status);
|
req_wrap->Done(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,6 +360,8 @@ int StreamWrap::DoWrite(WriteWrap* w,
|
|||||||
|
|
||||||
void StreamWrap::AfterWrite(uv_write_t* req, int status) {
|
void StreamWrap::AfterWrite(uv_write_t* req, int status) {
|
||||||
WriteWrap* req_wrap = ContainerOf(&WriteWrap::req_, req);
|
WriteWrap* req_wrap = ContainerOf(&WriteWrap::req_, req);
|
||||||
|
HandleScope scope(req_wrap->env()->isolate());
|
||||||
|
Context::Scope context_scope(req_wrap->env()->context());
|
||||||
req_wrap->Done(status);
|
req_wrap->Done(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ using v8::Function;
|
|||||||
using v8::FunctionCallbackInfo;
|
using v8::FunctionCallbackInfo;
|
||||||
using v8::FunctionTemplate;
|
using v8::FunctionTemplate;
|
||||||
using v8::Handle;
|
using v8::Handle;
|
||||||
using v8::HandleScope;
|
|
||||||
using v8::Integer;
|
using v8::Integer;
|
||||||
using v8::Local;
|
using v8::Local;
|
||||||
using v8::Null;
|
using v8::Null;
|
||||||
@@ -251,8 +250,6 @@ void TLSWrap::SSLInfoCallback(const SSL* ssl_, int where, int ret) {
|
|||||||
SSL* ssl = const_cast<SSL*>(ssl_);
|
SSL* ssl = const_cast<SSL*>(ssl_);
|
||||||
TLSWrap* c = static_cast<TLSWrap*>(SSL_get_app_data(ssl));
|
TLSWrap* c = static_cast<TLSWrap*>(SSL_get_app_data(ssl));
|
||||||
Environment* env = c->env();
|
Environment* env = c->env();
|
||||||
HandleScope handle_scope(env->isolate());
|
|
||||||
Context::Scope context_scope(env->context());
|
|
||||||
Local<Object> object = c->object();
|
Local<Object> object = c->object();
|
||||||
|
|
||||||
if (where & SSL_CB_HANDSHAKE_START) {
|
if (where & SSL_CB_HANDSHAKE_START) {
|
||||||
@@ -395,9 +392,6 @@ void TLSWrap::ClearOut() {
|
|||||||
if (eof_)
|
if (eof_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HandleScope handle_scope(env()->isolate());
|
|
||||||
Context::Scope context_scope(env()->context());
|
|
||||||
|
|
||||||
CHECK_NE(ssl_, nullptr);
|
CHECK_NE(ssl_, nullptr);
|
||||||
|
|
||||||
char out[kClearOutChunkSize];
|
char out[kClearOutChunkSize];
|
||||||
@@ -470,9 +464,6 @@ bool TLSWrap::ClearIn() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleScope handle_scope(env()->isolate());
|
|
||||||
Context::Scope context_scope(env()->context());
|
|
||||||
|
|
||||||
// Error or partial write
|
// Error or partial write
|
||||||
int err;
|
int err;
|
||||||
Local<Value> arg = GetSSLError(written, &err, &error_);
|
Local<Value> arg = GetSSLError(written, &err, &error_);
|
||||||
@@ -588,8 +579,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
|
|||||||
|
|
||||||
if (i != count) {
|
if (i != count) {
|
||||||
int err;
|
int err;
|
||||||
HandleScope handle_scope(env()->isolate());
|
|
||||||
Context::Scope context_scope(env()->context());
|
|
||||||
Local<Value> arg = GetSSLError(written, &err, &error_);
|
Local<Value> arg = GetSSLError(written, &err, &error_);
|
||||||
if (!arg.IsEmpty())
|
if (!arg.IsEmpty())
|
||||||
return UV_EPROTO;
|
return UV_EPROTO;
|
||||||
@@ -662,8 +651,6 @@ void TLSWrap::DoRead(ssize_t nread,
|
|||||||
eof_ = true;
|
eof_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleScope handle_scope(env()->isolate());
|
|
||||||
Context::Scope context_scope(env()->context());
|
|
||||||
OnRead(nread, nullptr);
|
OnRead(nread, nullptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -796,7 +783,6 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
|
|||||||
if (servername == nullptr)
|
if (servername == nullptr)
|
||||||
return SSL_TLSEXT_ERR_OK;
|
return SSL_TLSEXT_ERR_OK;
|
||||||
|
|
||||||
HandleScope scope(env->isolate());
|
|
||||||
// Call the SNI callback and use its return value as context
|
// Call the SNI callback and use its return value as context
|
||||||
Local<Object> object = p->object();
|
Local<Object> object = p->object();
|
||||||
Local<Value> ctx = object->Get(env->sni_context_string());
|
Local<Value> ctx = object->Get(env->sni_context_string());
|
||||||
|
|||||||
Reference in new issue
Block a user