From c253e39b56500e8791d3d70664f233b8e518d164 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Sun, 12 Nov 2023 23:52:03 +0900 Subject: [PATCH] src: handle errors from uv_pipe_connect2() We need to handle errors from uv_pipe_connect2() because return type is `int`. Fixes: https://github.com/nodejs/node/issues/50652 Refs: https://github.com/nodejs/node/pull/49667 Refs: https://github.com/libuv/libuv/pull/4030 PR-URL: https://github.com/nodejs/node/pull/50657 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: theanarkh --- src/pipe_wrap.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 738a51a140d0af..e6f1f38120db71 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -225,16 +225,19 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP); - req_wrap->Dispatch( + int err = req_wrap->Dispatch( uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect); + if (err) { + delete req_wrap; + } else { + TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE2(net, native), + "connect", + req_wrap, + "pipe_path", + TRACE_STR_COPY(*name)); + } - TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE2(net, native), - "connect", - req_wrap, - "pipe_path", - TRACE_STR_COPY(*name)); - - args.GetReturnValue().Set(0); // uv_pipe_connect() doesn't return errors. + args.GetReturnValue().Set(err); } } // namespace node