win: add uv__once_init() calls
Some functions, such as uv_fs_scandir() can be called with a NULL loop argument. In this case, it's possible that the Windows API hasn't been initialized, leading to a crash. This commit adds additional uv__once_init() calls to mitigate this situation. Fixes: https://github.com/libuv/libuv/issues/1488 PR-URL: https://github.com/libuv/libuv/pull/1512 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
36ea2cb295
commit
165c63b96c
@ -221,6 +221,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
|
||||
|
||||
INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req,
|
||||
uv_fs_type fs_type, const uv_fs_cb cb) {
|
||||
uv__once_init();
|
||||
UV_REQ_INIT(req, UV_FS);
|
||||
req->loop = loop;
|
||||
req->flags = 0;
|
||||
|
||||
@ -1913,6 +1913,7 @@ int uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
|
||||
if (os_handle == INVALID_HANDLE_VALUE)
|
||||
return UV_EBADF;
|
||||
|
||||
uv__once_init();
|
||||
/* In order to avoid closing a stdio file descriptor 0-2, duplicate the
|
||||
* underlying OS handle and forget about the original fd.
|
||||
* We could also opt to use the original OS handle and just never close it,
|
||||
@ -1986,6 +1987,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
|
||||
unsigned int name_len;
|
||||
int err;
|
||||
|
||||
uv__once_init();
|
||||
name_info = NULL;
|
||||
|
||||
if (handle->handle == INVALID_HANDLE_VALUE) {
|
||||
|
||||
@ -148,6 +148,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
|
||||
HANDLE handle;
|
||||
CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
|
||||
|
||||
uv__once_init();
|
||||
handle = (HANDLE) uv__get_osfhandle(fd);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return UV_EBADF;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user