From 49a2e406329269af2bf55c0ad51560bdf1f14b7f Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 16 Feb 2019 13:54:22 +0100 Subject: src: move req_wrap_queue to base class of ReqWrap Introduce a second base class for `ReqWrap` that does not depend on a template parameter and move the `req_wrap_queue_` field to it. This addresses undefined behaviour that occurs when casting to `ReqWrap` in the `ReqWrap` constructor. Refs: https://github.com/nodejs/node/issues/26131 PR-URL: https://github.com/nodejs/node/pull/26148 Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell --- src/req_wrap-inl.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/req_wrap-inl.h') diff --git a/src/req_wrap-inl.h b/src/req_wrap-inl.h index 4f9da1c4f3..5fb9654148 100644 --- a/src/req_wrap-inl.h +++ b/src/req_wrap-inl.h @@ -11,16 +11,16 @@ namespace node { +ReqWrapBase::ReqWrapBase(Environment* env) { + env->req_wrap_queue()->PushBack(this); +} + template ReqWrap::ReqWrap(Environment* env, v8::Local object, AsyncWrap::ProviderType provider) - : AsyncWrap(env, object, provider) { - - // FIXME(bnoordhuis) The fact that a reinterpret_cast is needed is - // arguably a good indicator that there should be more than one queue. - env->req_wrap_queue()->PushBack(reinterpret_cast*>(this)); - + : AsyncWrap(env, object, provider), + ReqWrapBase(env) { Reset(); } @@ -51,6 +51,11 @@ void ReqWrap::Cancel() { uv_cancel(reinterpret_cast(&req_)); } +template +AsyncWrap* ReqWrap::GetAsyncWrap() { + return this; +} + // Below is dark template magic designed to invoke libuv functions that // initialize uv_req_t instances in a unified fashion, to allow easier // tracking of active/inactive requests. -- cgit v1.2.3