From 247d1e4ddb4be12072a202a35c43dfbdc96cbeb0 Mon Sep 17 00:00:00 2001 From: Purva Vasudeo Date: Thu, 9 Jul 2020 10:45:23 -0700 Subject: [PATCH] Clean old handle before creating a new one Clean old handle before creating a new one --- src/iisnode/cprotocolbridge.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/iisnode/cprotocolbridge.cpp b/src/iisnode/cprotocolbridge.cpp index ec7b2a75..996af08f 100644 --- a/src/iisnode/cprotocolbridge.cpp +++ b/src/iisnode/cprotocolbridge.cpp @@ -626,6 +626,12 @@ void WINAPI CProtocolBridge::CreateNamedPipeConnection(DWORD error, DWORD bytesT if (INVALID_HANDLE_VALUE == pipe) { + // Clean up old pipe handle, otherwise there will be a handle leak + HANDLE oldPipe = ctx->GetPipe(); + if (oldPipe != NULL && oldPipe != INVALID_HANDLE_VALUE) { + CloseHandle(oldPipe); + } + ErrorIf(INVALID_HANDLE_VALUE == (pipe = CreateFile( ctx->GetNodeProcess()->GetNamedPipeName(), GENERIC_READ | GENERIC_WRITE,