Skip to content

Commit

Permalink
Fix handle cleanup code (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 committed Oct 4, 2023
1 parent a5f1d72 commit d6ce76a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ static void OnProcessExit(uv_async_t *async) {
DWORD exitCode = 0;
GetExitCodeProcess(baton->hShell, &exitCode);

// Clean up handles
// Calling DisconnectNamedPipes here or in PtyKill results in a crash,
// ref https://github.com/microsoft/node-pty/issues/512,
// so we only call CloseHandle for now.
CloseHandle(baton->hIn);
CloseHandle(baton->hOut);

// Call function
v8::Local<v8::Value> args[1] = {
Nan::New<v8::Number>(exitCode)
Expand Down Expand Up @@ -476,10 +483,6 @@ static NAN_METHOD(PtyKill) {
}
}

DisconnectNamedPipe(handle->hIn);
DisconnectNamedPipe(handle->hOut);
CloseHandle(handle->hIn);
CloseHandle(handle->hOut);
CloseHandle(handle->hShell);
}

Expand Down

0 comments on commit d6ce76a

Please sign in to comment.