From 164fbda67ec8b4268750a919b9b189c98980027a Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 10 Jun 2015 17:13:42 -0700 Subject: [PATCH] win,tty: properly close when created from CRT fd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a Windows handle was opened from a CRT fd, it needs to be closed with `close()` instead of `CloseHandle()`. PR-URL: https://github.com/libuv/libuv/pull/396 Reviewed-By: Saúl Ibarra Corretgé --- src/win/tty.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/win/tty.c b/src/win/tty.c index 781768493..349e20645 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -135,6 +135,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) { uv_connection_init((uv_stream_t*) tty); tty->handle = handle; + tty->u.fd = fd; tty->reqs_pending = 0; tty->flags |= UV_HANDLE_BOUND; @@ -1915,11 +1916,15 @@ void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle, void uv_tty_close(uv_tty_t* handle) { - CloseHandle(handle->handle); + if (handle->u.fd == -1) + CloseHandle(handle->handle); + else + close(handle->u.fd); if (handle->flags & UV_HANDLE_READING) uv_tty_read_stop(handle); + handle->u.fd = -1; handle->handle = INVALID_HANDLE_VALUE; handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE); uv__handle_closing(handle);