aboutsummaryrefslogtreecommitdiff
path: root/deps/uv/src/win
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/win')
-rw-r--r--deps/uv/src/win/fs-event.c75
-rw-r--r--deps/uv/src/win/fs.c34
-rw-r--r--deps/uv/src/win/getaddrinfo.c10
-rw-r--r--deps/uv/src/win/pipe.c42
-rw-r--r--deps/uv/src/win/process-stdio.c4
-rw-r--r--deps/uv/src/win/process.c44
-rw-r--r--deps/uv/src/win/tcp.c6
-rw-r--r--deps/uv/src/win/thread.c6
-rw-r--r--deps/uv/src/win/util.c147
9 files changed, 216 insertions, 152 deletions
diff --git a/deps/uv/src/win/fs-event.c b/deps/uv/src/win/fs-event.c
index 640651b6c9..eb205d3921 100644
--- a/deps/uv/src/win/fs-event.c
+++ b/deps/uv/src/win/fs-event.c
@@ -72,13 +72,13 @@ static int uv_split_path(const WCHAR* filename, WCHAR** dir,
if (i == 0) {
if (dir) {
- *dir = (WCHAR*)malloc((MAX_PATH + 1) * sizeof(WCHAR));
+ *dir = (WCHAR*)uv__malloc((MAX_PATH + 1) * sizeof(WCHAR));
if (!*dir) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!GetCurrentDirectoryW(MAX_PATH, *dir)) {
- free(*dir);
+ uv__free(*dir);
*dir = NULL;
return -1;
}
@@ -87,17 +87,17 @@ static int uv_split_path(const WCHAR* filename, WCHAR** dir,
*file = wcsdup(filename);
} else {
if (dir) {
- *dir = (WCHAR*)malloc((i + 1) * sizeof(WCHAR));
+ *dir = (WCHAR*)uv__malloc((i + 1) * sizeof(WCHAR));
if (!*dir) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
wcsncpy(*dir, filename, i);
(*dir)[i] = L'\0';
}
- *file = (WCHAR*)malloc((len - i) * sizeof(WCHAR));
+ *file = (WCHAR*)uv__malloc((len - i) * sizeof(WCHAR));
if (!*file) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
wcsncpy(*file, filename + i + 1, len - i - 1);
(*file)[len - i - 1] = L'\0';
@@ -137,18 +137,18 @@ int uv_fs_event_start(uv_fs_event_t* handle,
return UV_EINVAL;
handle->cb = cb;
- handle->path = strdup(path);
+ handle->path = uv__strdup(path);
if (!handle->path) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
uv__handle_start(handle);
/* Convert name to UTF16. */
name_size = uv_utf8_to_utf16(path, NULL, 0) * sizeof(WCHAR);
- pathw = (WCHAR*)malloc(name_size);
+ pathw = (WCHAR*)uv__malloc(name_size);
if (!pathw) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!uv_utf8_to_utf16(path, pathw,
@@ -192,7 +192,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
}
dir_to_watch = dir;
- free(pathw);
+ uv__free(pathw);
pathw = NULL;
}
@@ -207,7 +207,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
NULL);
if (dir) {
- free(dir);
+ uv__free(dir);
dir = NULL;
}
@@ -225,11 +225,10 @@ int uv_fs_event_start(uv_fs_event_t* handle,
}
if (!handle->buffer) {
- handle->buffer = (char*)_aligned_malloc(uv_directory_watcher_buffer_size,
- sizeof(DWORD));
+ handle->buffer = (char*)uv__malloc(uv_directory_watcher_buffer_size);
}
if (!handle->buffer) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
memset(&(handle->req.u.io.overlapped), 0,
@@ -259,21 +258,21 @@ int uv_fs_event_start(uv_fs_event_t* handle,
error:
if (handle->path) {
- free(handle->path);
+ uv__free(handle->path);
handle->path = NULL;
}
if (handle->filew) {
- free(handle->filew);
+ uv__free(handle->filew);
handle->filew = NULL;
}
if (handle->short_filew) {
- free(handle->short_filew);
+ uv__free(handle->short_filew);
handle->short_filew = NULL;
}
- free(pathw);
+ uv__free(pathw);
if (handle->dir_handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle->dir_handle);
@@ -281,7 +280,7 @@ error:
}
if (handle->buffer) {
- _aligned_free(handle->buffer);
+ uv__free(handle->buffer);
handle->buffer = NULL;
}
@@ -301,22 +300,22 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
uv__handle_stop(handle);
if (handle->filew) {
- free(handle->filew);
+ uv__free(handle->filew);
handle->filew = NULL;
}
if (handle->short_filew) {
- free(handle->short_filew);
+ uv__free(handle->short_filew);
handle->short_filew = NULL;
}
if (handle->path) {
- free(handle->path);
+ uv__free(handle->path);
handle->path = NULL;
}
if (handle->dirw) {
- free(handle->dirw);
+ uv__free(handle->dirw);
handle->dirw = NULL;
}
@@ -378,9 +377,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
size = wcslen(handle->dirw) +
file_info->FileNameLength / sizeof(WCHAR) + 2;
- filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
+ filenamew = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
if (!filenamew) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
_snwprintf(filenamew, size, L"%s\\%.*s", handle->dirw,
@@ -393,26 +392,26 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
size = GetLongPathNameW(filenamew, NULL, 0);
if (size) {
- long_filenamew = (WCHAR*)malloc(size * sizeof(WCHAR));
+ long_filenamew = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
if (!long_filenamew) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
size = GetLongPathNameW(filenamew, long_filenamew, size);
if (size) {
long_filenamew[size] = '\0';
} else {
- free(long_filenamew);
+ uv__free(long_filenamew);
long_filenamew = NULL;
}
}
- free(filenamew);
+ uv__free(filenamew);
if (long_filenamew) {
/* Get the file name out of the long path. */
result = uv_split_path(long_filenamew, NULL, &filenamew);
- free(long_filenamew);
+ uv__free(long_filenamew);
if (result == 0) {
long_filenamew = filenamew;
@@ -447,9 +446,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
NULL,
0);
if (size) {
- filename = (char*)malloc(size + 1);
+ filename = (char*)uv__malloc(size + 1);
if (!filename) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
size = uv_utf16_to_utf8(filenamew,
@@ -459,7 +458,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
if (size) {
filename[size] = '\0';
} else {
- free(filename);
+ uv__free(filename);
filename = NULL;
}
}
@@ -478,9 +477,9 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
break;
}
- free(filename);
+ uv__free(filename);
filename = NULL;
- free(long_filenamew);
+ uv__free(long_filenamew);
long_filenamew = NULL;
}
@@ -519,7 +518,7 @@ void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
if (handle->buffer) {
- _aligned_free(handle->buffer);
+ uv__free(handle->buffer);
handle->buffer = NULL;
}
diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c
index af7ec74276..00d0197a54 100644
--- a/deps/uv/src/win/fs.c
+++ b/deps/uv/src/win/fs.c
@@ -166,7 +166,7 @@ INLINE static int fs__capture_path(uv_loop_t* loop, uv_fs_t* req,
return 0;
}
- buf = (char*) malloc(buf_sz);
+ buf = (char*) uv__malloc(buf_sz);
if (buf == NULL) {
return ERROR_OUTOFMEMORY;
}
@@ -352,7 +352,7 @@ INLINE static int fs__readlink_handle(HANDLE handle, char** target_ptr,
/* If requested, allocate memory and convert to UTF8. */
if (target_ptr != NULL) {
int r;
- target = (char*) malloc(target_len + 1);
+ target = (char*) uv__malloc(target_len + 1);
if (target == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return -1;
@@ -896,7 +896,7 @@ void fs__scandir(uv_fs_t* req) {
size_t new_dirents_size =
dirents_size == 0 ? dirents_initial_size : dirents_size << 1;
uv__dirent_t** new_dirents =
- realloc(dirents, new_dirents_size * sizeof *dirents);
+ uv__realloc(dirents, new_dirents_size * sizeof *dirents);
if (new_dirents == NULL)
goto out_of_memory_error;
@@ -909,7 +909,7 @@ void fs__scandir(uv_fs_t* req) {
* includes room for the first character of the filename, but `utf8_len`
* doesn't count the NULL terminator at this point.
*/
- dirent = malloc(sizeof *dirent + utf8_len);
+ dirent = uv__malloc(sizeof *dirent + utf8_len);
if (dirent == NULL)
goto out_of_memory_error;
@@ -998,9 +998,9 @@ cleanup:
if (dir_handle != INVALID_HANDLE_VALUE)
CloseHandle(dir_handle);
while (dirents_used > 0)
- free(dirents[--dirents_used]);
+ uv__free(dirents[--dirents_used]);
if (dirents != NULL)
- free(dirents);
+ uv__free(dirents);
}
@@ -1281,9 +1281,9 @@ static void fs__sendfile(uv_fs_t* req) {
size_t buf_size = length < max_buf_size ? length : max_buf_size;
int n, result = 0;
int64_t result_offset = 0;
- char* buf = (char*) malloc(buf_size);
+ char* buf = (char*) uv__malloc(buf_size);
if (!buf) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (offset != -1) {
@@ -1314,7 +1314,7 @@ static void fs__sendfile(uv_fs_t* req) {
}
}
- free(buf);
+ uv__free(buf);
SET_REQ_RESULT(req, result);
}
@@ -1504,9 +1504,9 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path,
2 * (target_len + 2) * sizeof(WCHAR);
/* Allocate the buffer */
- buffer = (REPARSE_DATA_BUFFER*)malloc(needed_buf_size);
+ buffer = (REPARSE_DATA_BUFFER*)uv__malloc(needed_buf_size);
if (!buffer) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
/* Grab a pointer to the part of the buffer where filenames go */
@@ -1620,13 +1620,13 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path,
/* Clean up */
CloseHandle(handle);
- free(buffer);
+ uv__free(buffer);
SET_REQ_RESULT(req, 0);
return;
error:
- free(buffer);
+ uv__free(buffer);
if (handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle);
@@ -1764,10 +1764,10 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
return;
if (req->flags & UV_FS_FREE_PATHS)
- free(req->file.pathw);
+ uv__free(req->file.pathw);
if (req->flags & UV_FS_FREE_PTR)
- free(req->ptr);
+ uv__free(req->ptr);
req->path = NULL;
req->file.pathw = NULL;
@@ -1830,7 +1830,7 @@ int uv_fs_read(uv_loop_t* loop,
req->fs.info.nbufs = nbufs;
req->fs.info.bufs = req->fs.info.bufsml;
if (nbufs > ARRAY_SIZE(req->fs.info.bufsml))
- req->fs.info.bufs = malloc(nbufs * sizeof(*bufs));
+ req->fs.info.bufs = uv__malloc(nbufs * sizeof(*bufs));
if (req->fs.info.bufs == NULL)
return UV_ENOMEM;
@@ -1863,7 +1863,7 @@ int uv_fs_write(uv_loop_t* loop,
req->fs.info.nbufs = nbufs;
req->fs.info.bufs = req->fs.info.bufsml;
if (nbufs > ARRAY_SIZE(req->fs.info.bufsml))
- req->fs.info.bufs = malloc(nbufs * sizeof(*bufs));
+ req->fs.info.bufs = uv__malloc(nbufs * sizeof(*bufs));
if (req->fs.info.bufs == NULL)
return UV_ENOMEM;
diff --git a/deps/uv/src/win/getaddrinfo.c b/deps/uv/src/win/getaddrinfo.c
index f3802cd582..3d23660e88 100644
--- a/deps/uv/src/win/getaddrinfo.c
+++ b/deps/uv/src/win/getaddrinfo.c
@@ -110,7 +110,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
/* release input parameter memory */
if (req->alloc != NULL) {
- free(req->alloc);
+ uv__free(req->alloc);
req->alloc = NULL;
}
@@ -139,7 +139,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
}
/* allocate memory for addrinfo results */
- alloc_ptr = (char*)malloc(addrinfo_len);
+ alloc_ptr = (char*)uv__malloc(addrinfo_len);
/* do conversions */
if (alloc_ptr != NULL) {
@@ -220,7 +220,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
/* release copied result memory */
if (alloc_ptr != NULL) {
- free(alloc_ptr);
+ uv__free(alloc_ptr);
}
}
@@ -285,7 +285,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
}
/* allocate memory for inputs, and partition it as needed */
- alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize);
+ alloc_ptr = (char*)uv__malloc(nodesize + servicesize + hintssize);
if (!alloc_ptr) {
err = WSAENOBUFS;
goto error;
@@ -355,7 +355,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
error:
if (req != NULL && req->alloc != NULL) {
- free(req->alloc);
+ uv__free(req->alloc);
}
return uv_translate_sys_error(err);
}
diff --git a/deps/uv/src/win/pipe.c b/deps/uv/src/win/pipe.c
index 5a0e542084..d232efae3a 100644
--- a/deps/uv/src/win/pipe.c
+++ b/deps/uv/src/win/pipe.c
@@ -423,7 +423,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
&item->socket_info_ex.socket_info,
0,
WSA_FLAG_OVERLAPPED);
- free(item);
+ uv__free(item);
if (socket != INVALID_SOCKET)
closesocket(socket);
@@ -444,7 +444,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
if (handle->flags & UV_HANDLE_PIPESERVER) {
assert(handle->pipe.serv.accept_reqs);
- free(handle->pipe.serv.accept_reqs);
+ uv__free(handle->pipe.serv.accept_reqs);
handle->pipe.serv.accept_reqs = NULL;
}
@@ -478,9 +478,9 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
}
handle->pipe.serv.accept_reqs = (uv_pipe_accept_t*)
- malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances);
+ uv__malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances);
if (!handle->pipe.serv.accept_reqs) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
@@ -494,9 +494,9 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
/* Convert name to UTF16. */
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(WCHAR);
- handle->name = (WCHAR*)malloc(nameSize);
+ handle->name = (WCHAR*)uv__malloc(nameSize);
if (!handle->name) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
@@ -540,7 +540,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
error:
if (handle->name) {
- free(handle->name);
+ uv__free(handle->name);
handle->name = NULL;
}
@@ -607,9 +607,9 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
/* Convert name to UTF16. */
nameSize = uv_utf8_to_utf16(name, NULL, 0) * sizeof(WCHAR);
- handle->name = (WCHAR*)malloc(nameSize);
+ handle->name = (WCHAR*)uv__malloc(nameSize);
if (!handle->name) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(WCHAR))) {
@@ -656,7 +656,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
error:
if (handle->name) {
- free(handle->name);
+ uv__free(handle->name);
handle->name = NULL;
}
@@ -717,7 +717,7 @@ void uv_pipe_cleanup(uv_loop_t* loop, uv_pipe_t* handle) {
uv__pipe_stop_read(handle);
if (handle->name) {
- free(handle->name);
+ uv__free(handle->name);
handle->name = NULL;
}
@@ -845,7 +845,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
if (err != 0)
return err;
- free(item);
+ uv__free(item);
} else {
pipe_client = (uv_pipe_t*)client;
@@ -1261,9 +1261,9 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
if (handle->pipe.conn.ipc_header_write_req.type != UV_WRITE) {
ipc_header_req = (uv_write_t*)&handle->pipe.conn.ipc_header_write_req;
} else {
- ipc_header_req = (uv_write_t*)malloc(sizeof(uv_write_t));
+ ipc_header_req = (uv_write_t*)uv__malloc(sizeof(uv_write_t));
if (!ipc_header_req) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
}
@@ -1498,9 +1498,9 @@ void uv__pipe_insert_pending_socket(uv_pipe_t* handle,
int tcp_connection) {
uv__ipc_queue_item_t* item;
- item = (uv__ipc_queue_item_t*) malloc(sizeof(*item));
+ item = (uv__ipc_queue_item_t*) uv__malloc(sizeof(*item));
if (item == NULL)
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
memcpy(&item->socket_info_ex, info, sizeof(item->socket_info_ex));
item->tcp_connection = tcp_connection;
@@ -1667,7 +1667,7 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
if (req == &handle->pipe.conn.ipc_header_write_req) {
req->type = UV_UNKNOWN_REQ;
} else {
- free(req);
+ uv__free(req);
}
} else {
if (req->cb) {
@@ -1788,7 +1788,7 @@ static void eof_timer_init(uv_pipe_t* pipe) {
assert(pipe->pipe.conn.eof_timer == NULL);
assert(pipe->flags & UV_HANDLE_CONNECTION);
- pipe->pipe.conn.eof_timer = (uv_timer_t*) malloc(sizeof *pipe->pipe.conn.eof_timer);
+ pipe->pipe.conn.eof_timer = (uv_timer_t*) uv__malloc(sizeof *pipe->pipe.conn.eof_timer);
r = uv_timer_init(pipe->loop, pipe->pipe.conn.eof_timer);
assert(r == 0); /* timers can't fail */
@@ -1863,7 +1863,7 @@ static void eof_timer_destroy(uv_pipe_t* pipe) {
static void eof_timer_close_cb(uv_handle_t* handle) {
assert(handle->type == UV_TIMER);
- free(handle);
+ uv__free(handle);
}
@@ -1941,7 +1941,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
FileNameInformation);
if (nt_status == STATUS_BUFFER_OVERFLOW) {
name_size = sizeof(*name_info) + tmp_name_info.FileNameLength;
- name_info = malloc(name_size);
+ name_info = uv__malloc(name_size);
if (!name_info) {
*size = 0;
err = UV_ENOMEM;
@@ -2020,7 +2020,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
goto cleanup;
error:
- free(name_info);
+ uv__free(name_info);
cleanup:
uv__pipe_unpause_read((uv_pipe_t*)handle); /* cast away const warning */
diff --git a/deps/uv/src/win/process-stdio.c b/deps/uv/src/win/process-stdio.c
index 98566da651..e81f799f0b 100644
--- a/deps/uv/src/win/process-stdio.c
+++ b/deps/uv/src/win/process-stdio.c
@@ -279,7 +279,7 @@ int uv__stdio_create(uv_loop_t* loop,
}
/* Allocate the child stdio buffer */
- buffer = (BYTE*) malloc(CHILD_STDIO_SIZE(count));
+ buffer = (BYTE*) uv__malloc(CHILD_STDIO_SIZE(count));
if (buffer == NULL) {
return ERROR_OUTOFMEMORY;
}
@@ -459,7 +459,7 @@ void uv__stdio_destroy(BYTE* buffer) {
}
}
- free(buffer);
+ uv__free(buffer);
}
diff --git a/deps/uv/src/win/process.c b/deps/uv/src/win/process.c
index 887595f89c..855c374081 100644
--- a/deps/uv/src/win/process.c
+++ b/deps/uv/src/win/process.c
@@ -25,8 +25,8 @@
#include <stdlib.h>
#include <signal.h>
#include <limits.h>
-#include <malloc.h>
#include <wchar.h>
+#include <malloc.h> /* alloca */
#include "uv.h"
#include "internal.h"
@@ -120,7 +120,7 @@ static int uv_utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
return GetLastError();
}
- ws = (WCHAR*) malloc(ws_len * sizeof(WCHAR));
+ ws = (WCHAR*) uv__malloc(ws_len * sizeof(WCHAR));
if (ws == NULL) {
return ERROR_OUTOFMEMORY;
}
@@ -197,7 +197,7 @@ static WCHAR* search_path_join_test(const WCHAR* dir,
}
/* Allocate buffer for output */
- result = result_pos = (WCHAR*)malloc(sizeof(WCHAR) *
+ result = result_pos = (WCHAR*)uv__malloc(sizeof(WCHAR) *
(cwd_len + 1 + dir_len + 1 + name_len + 1 + ext_len + 1));
/* Copy cwd */
@@ -246,7 +246,7 @@ static WCHAR* search_path_join_test(const WCHAR* dir,
return result;
}
- free(result);
+ uv__free(result);
return NULL;
}
@@ -555,14 +555,14 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
dst_len = dst_len * 2 + arg_count * 2;
/* Allocate buffer for the final command line. */
- dst = (WCHAR*) malloc(dst_len * sizeof(WCHAR));
+ dst = (WCHAR*) uv__malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
}
/* Allocate temporary working buffer. */
- temp_buffer = (WCHAR*) malloc(temp_buffer_len * sizeof(WCHAR));
+ temp_buffer = (WCHAR*) uv__malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
@@ -596,14 +596,14 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
*pos++ = *(arg + 1) ? L' ' : L'\0';
}
- free(temp_buffer);
+ uv__free(temp_buffer);
*dst_ptr = dst;
return 0;
error:
- free(dst);
- free(temp_buffer);
+ uv__free(dst);
+ uv__free(temp_buffer);
return err;
}
@@ -707,7 +707,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
}
/* second pass: copy to UTF-16 environment block */
- dst_copy = malloc(env_len * sizeof(WCHAR));
+ dst_copy = (WCHAR*)uv__malloc(env_len * sizeof(WCHAR));
if (!dst_copy) {
return ERROR_OUTOFMEMORY;
}
@@ -725,7 +725,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
(int) (env_len - (ptr - dst_copy)));
if (len <= 0) {
DWORD err = GetLastError();
- free(dst_copy);
+ uv__free(dst_copy);
return err;
}
*ptr_copy++ = ptr;
@@ -765,9 +765,9 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
}
/* final pass: copy, in sort order, and inserting required variables */
- dst = malloc((1+env_len) * sizeof(WCHAR));
+ dst = uv__malloc((1+env_len) * sizeof(WCHAR));
if (!dst) {
- free(dst_copy);
+ uv__free(dst_copy);
return ERROR_OUTOFMEMORY;
}
@@ -812,7 +812,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
assert(env_len == (ptr - dst));
*ptr = L'\0';
- free(dst_copy);
+ uv__free(dst_copy);
*dst_ptr = dst;
return 0;
}
@@ -988,7 +988,7 @@ int uv_spawn(uv_loop_t* loop,
goto done;
}
- cwd = (WCHAR*) malloc(cwd_len * sizeof(WCHAR));
+ cwd = (WCHAR*) uv__malloc(cwd_len * sizeof(WCHAR));
if (cwd == NULL) {
err = ERROR_OUTOFMEMORY;
goto done;
@@ -1012,7 +1012,7 @@ int uv_spawn(uv_loop_t* loop,
goto done;
}
- alloc_path = (WCHAR*) malloc(path_len * sizeof(WCHAR));
+ alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR));
if (alloc_path == NULL) {
err = ERROR_OUTOFMEMORY;
goto done;
@@ -1146,12 +1146,12 @@ int uv_spawn(uv_loop_t* loop,
/* Cleanup, whether we succeeded or failed. */
done:
- free(application);
- free(application_path);
- free(arguments);
- free(cwd);
- free(env);
- free(alloc_path);
+ uv__free(application);
+ uv__free(application_path);
+ uv__free(arguments);
+ uv__free(cwd);
+ uv__free(env);
+ uv__free(alloc_path);
if (process->child_stdio_buffer != NULL) {
/* Clean up child stdio handles. */
diff --git a/deps/uv/src/win/tcp.c b/deps/uv/src/win/tcp.c
index 8b0e18c7cf..da89f28d16 100644
--- a/deps/uv/src/win/tcp.c
+++ b/deps/uv/src/win/tcp.c
@@ -215,7 +215,7 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
}
}
- free(handle->tcp.serv.accept_reqs);
+ uv__free(handle->tcp.serv.accept_reqs);
handle->tcp.serv.accept_reqs = NULL;
}
@@ -564,9 +564,9 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
if(!handle->tcp.serv.accept_reqs) {
handle->tcp.serv.accept_reqs = (uv_tcp_accept_t*)
- malloc(uv_simultaneous_server_accepts * sizeof(uv_tcp_accept_t));
+ uv__malloc(uv_simultaneous_server_accepts * sizeof(uv_tcp_accept_t));
if (!handle->tcp.serv.accept_reqs) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
for (i = 0; i < simultaneous_accepts; i++) {
diff --git a/deps/uv/src/win/thread.c b/deps/uv/src/win/thread.c
index 9d273a56e7..e91ae9b138 100644
--- a/deps/uv/src/win/thread.c
+++ b/deps/uv/src/win/thread.c
@@ -134,7 +134,7 @@ static UINT __stdcall uv__thread_start(void* arg) {
ctx_p = arg;
ctx = *ctx_p;
- free(ctx_p);
+ uv__free(ctx_p);
uv_once(&uv__current_thread_init_guard, uv__init_current_thread_key);
uv_key_set(&uv__current_thread_key, (void*) ctx.self);
@@ -150,7 +150,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
int err;
HANDLE thread;
- ctx = malloc(sizeof(*ctx));
+ ctx = uv__malloc(sizeof(*ctx));
if (ctx == NULL)
return UV_ENOMEM;
@@ -167,7 +167,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
NULL);
if (thread == NULL) {
err = errno;
- free(ctx);
+ uv__free(ctx);
} else {
err = 0;
*tid = thread;
diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c
index 3697d5aa6a..a0d1307f8a 100644
--- a/deps/uv/src/win/util.c
+++ b/deps/uv/src/win/util.c
@@ -36,6 +36,7 @@
#include <psapi.h>
#include <tlhelp32.h>
#include <windows.h>
+#include <userenv.h>
/*
@@ -72,7 +73,7 @@ void uv__util_init() {
InitializeCriticalSection(&process_title_lock);
/* Retrieve high-resolution timer frequency
- * and precompute its reciprocal.
+ * and precompute its reciprocal.
*/
if (QueryPerformanceFrequency(&perf_frequency)) {
hrtime_interval_ = 1.0 / perf_frequency.QuadPart;
@@ -122,7 +123,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
utf16_buffer_len = (int) *size_ptr;
}
- utf16_buffer = (WCHAR*) malloc(sizeof(WCHAR) * utf16_buffer_len);
+ utf16_buffer = (WCHAR*) uv__malloc(sizeof(WCHAR) * utf16_buffer_len);
if (!utf16_buffer) {
return UV_ENOMEM;
}
@@ -151,7 +152,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
goto error;
}
- free(utf16_buffer);
+ uv__free(utf16_buffer);
/* utf8_len *does* include the terminating null at this point, but the */
/* returned size shouldn't. */
@@ -159,7 +160,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
return 0;
error:
- free(utf16_buffer);
+ uv__free(utf16_buffer);
return uv_translate_sys_error(err);
}
@@ -378,9 +379,9 @@ int uv_set_process_title(const char* title) {
}
/* Convert to wide-char string */
- title_w = (WCHAR*)malloc(sizeof(WCHAR) * length);
+ title_w = (WCHAR*)uv__malloc(sizeof(WCHAR) * length);
if (!title_w) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
length = uv_utf8_to_utf16(title, title_w, length);
@@ -400,14 +401,14 @@ int uv_set_process_title(const char* title) {
}
EnterCriticalSection(&process_title_lock);
- free(process_title);
- process_title = strdup(title);
+ uv__free(process_title);
+ process_title = uv__strdup(title);
LeaveCriticalSection(&process_title_lock);
err = 0;
done:
- free(title_w);
+ uv__free(title_w);
return uv_translate_sys_error(err);
}
@@ -427,14 +428,14 @@ static int uv__get_process_title() {
}
assert(!process_title);
- process_title = (char*)malloc(length);
+ process_title = (char*)uv__malloc(length);
if (!process_title) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
/* Do utf16 -> utf8 conversion here */
if (!uv_utf16_to_utf8(title_w, -1, process_title, length)) {
- free(process_title);
+ uv__free(process_title);
return -1;
}
@@ -540,9 +541,9 @@ int uv_uptime(double* uptime) {
goto internalError;
}
- free(malloced_buffer);
+ uv__free(malloced_buffer);
- buffer = malloced_buffer = (BYTE*) malloc(buffer_size);
+ buffer = malloced_buffer = (BYTE*) uv__malloc(buffer_size);
if (malloced_buffer == NULL) {
*uptime = 0;
return UV_ENOMEM;
@@ -584,7 +585,7 @@ int uv_uptime(double* uptime) {
uint64_t value = *((uint64_t*) address);
*uptime = (double) (object_type->PerfTime.QuadPart - value) /
(double) object_type->PerfFreq.QuadPart;
- free(malloced_buffer);
+ uv__free(malloced_buffer);
return 0;
}
}
@@ -594,12 +595,12 @@ int uv_uptime(double* uptime) {
}
/* If we get here, the uptime value was not found. */
- free(malloced_buffer);
+ uv__free(malloced_buffer);
*uptime = 0;
return UV_ENOSYS;
internalError:
- free(malloced_buffer);
+ uv__free(malloced_buffer);
*uptime = 0;
return UV_EIO;
}
@@ -625,14 +626,14 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
GetSystemInfo(&system_info);
cpu_count = system_info.dwNumberOfProcessors;
- cpu_infos = calloc(cpu_count, sizeof *cpu_infos);
+ cpu_infos = uv__calloc(cpu_count, sizeof *cpu_infos);
if (cpu_infos == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
}
sppi_size = cpu_count * sizeof(*sppi);
- sppi = malloc(sppi_size);
+ sppi = uv__malloc(sppi_size);
if (sppi == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
@@ -725,7 +726,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
assert(len > 0);
/* Allocate 1 extra byte for the null terminator. */
- cpu_info->model = malloc(len + 1);
+ cpu_info->model = uv__malloc(len + 1);
if (cpu_info->model == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
@@ -747,7 +748,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
cpu_info->model[len] = '\0';
}
- free(sppi);
+ uv__free(sppi);
*cpu_count_ptr = cpu_count;
*cpu_infos_ptr = cpu_infos;
@@ -757,10 +758,10 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
error:
/* This is safe because the cpu_infos array is zeroed on allocation. */
for (i = 0; i < cpu_count; i++)
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
- free(cpu_infos);
- free(sppi);
+ uv__free(cpu_infos);
+ uv__free(sppi);
return uv_translate_sys_error(err);
}
@@ -770,10 +771,10 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;
for (i = 0; i < count; i++) {
- free(cpu_infos[i].model);
+ uv__free(cpu_infos[i].model);
}
- free(cpu_infos);
+ uv__free(cpu_infos);
}
@@ -801,8 +802,8 @@ static int is_windows_version_or_greater(DWORD os_major,
/* Perform the test. */
return (int) VerifyVersionInfo(
- &osvi,
- VER_MAJORVERSION | VER_MINORVERSION |
+ &osvi,
+ VER_MAJORVERSION | VER_MINORVERSION |
VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
condition_mask);
}
@@ -870,7 +871,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_INCLUDE_PREFIX;
}
-
+
/* Fetch the size of the adapters reported by windows, and then get the */
/* list itself. */
@@ -892,13 +893,13 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
if (r == ERROR_SUCCESS)
break;
- free(win_address_buf);
+ uv__free(win_address_buf);
switch (r) {
case ERROR_BUFFER_OVERFLOW:
/* This happens when win_address_buf is NULL or too small to hold */
/* all adapters. */
- win_address_buf = malloc(win_address_buf_size);
+ win_address_buf = uv__malloc(win_address_buf_size);
if (win_address_buf == NULL)
return UV_ENOMEM;
@@ -906,7 +907,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
case ERROR_NO_DATA: {
/* No adapters were found. */
- uv_address_buf = malloc(1);
+ uv_address_buf = uv__malloc(1);
if (uv_address_buf == NULL)
return UV_ENOMEM;
@@ -966,7 +967,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
NULL,
FALSE);
if (name_size <= 0) {
- free(win_address_buf);
+ uv__free(win_address_buf);
return uv_translate_sys_error(GetLastError());
}
uv_address_buf_size += name_size;
@@ -983,9 +984,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
}
/* Allocate space to store interface data plus adapter names. */
- uv_address_buf = malloc(uv_address_buf_size);
+ uv_address_buf = uv__malloc(uv_address_buf_size);
if (uv_address_buf == NULL) {
- free(win_address_buf);
+ uv__free(win_address_buf);
return UV_ENOMEM;
}
@@ -1019,8 +1020,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
NULL,
FALSE);
if (name_size <= 0) {
- free(win_address_buf);
- free(uv_address_buf);
+ uv__free(win_address_buf);
+ uv__free(uv_address_buf);
return uv_translate_sys_error(GetLastError());
}
@@ -1053,14 +1054,14 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
prefix->PrefixLength <= prefix_len)
continue;
- if (address_prefix_match(sa->sa_family, sa,
+ if (address_prefix_match(sa->sa_family, sa,
prefix->Address.lpSockaddr, prefix->PrefixLength)) {
prefix_len = prefix->PrefixLength;
}
}
/* If there is no matching prefix information, return a single-host
- * subnet mask (e.g. 255.255.255.255 for IPv4).
+ * subnet mask (e.g. 255.255.255.255 for IPv4).
*/
if (!prefix_len)
prefix_len = (sa->sa_family == AF_INET6) ? 128 : 32;
@@ -1104,7 +1105,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
name_buf += name_size;
}
- free(win_address_buf);
+ uv__free(win_address_buf);
*addresses_ptr = uv_address_buf;
*count_ptr = count;
@@ -1115,7 +1116,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
- free(addresses);
+ uv__free(addresses);
}
@@ -1153,3 +1154,67 @@ int uv_getrusage(uv_rusage_t *uv_rusage) {
return 0;
}
+
+
+int uv_os_homedir(char* buffer, size_t* size) {
+ HANDLE token;
+ wchar_t path[MAX_PATH];
+ DWORD bufsize;
+ size_t len;
+ int r;
+
+ if (buffer == NULL || size == NULL || *size == 0)
+ return UV_EINVAL;
+
+ /* Check if the USERPROFILE environment variable is set first */
+ len = GetEnvironmentVariableW(L"USERPROFILE", path, MAX_PATH);
+
+ if (len == 0) {
+ r = GetLastError();
+ /* Don't return an error if USERPROFILE was not found */
+ if (r != ERROR_ENVVAR_NOT_FOUND)
+ return uv_translate_sys_error(r);
+ } else if (len > MAX_PATH) {
+ /* This should not be possible */
+ return UV_EIO;
+ } else {
+ goto convert_buffer;
+ }
+
+ /* USERPROFILE is not set, so call GetUserProfileDirectoryW() */
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token) == 0)
+ return uv_translate_sys_error(GetLastError());
+
+ bufsize = MAX_PATH;
+ if (!GetUserProfileDirectoryW(token, path, &bufsize)) {
+ r = GetLastError();
+ CloseHandle(token);
+
+ /* This should not be possible */
+ if (r == ERROR_INSUFFICIENT_BUFFER)
+ return UV_EIO;
+
+ return uv_translate_sys_error(r);
+ }
+
+ CloseHandle(token);
+
+convert_buffer:
+
+ /* Check how much space we need */
+ bufsize = uv_utf16_to_utf8(path, -1, NULL, 0);
+ if (bufsize == 0) {
+ return uv_translate_sys_error(GetLastError());
+ } else if (bufsize > *size) {
+ *size = bufsize - 1;
+ return UV_ENOBUFS;
+ }
+
+ /* Convert to UTF-8 */
+ bufsize = uv_utf16_to_utf8(path, -1, buffer, *size);
+ if (bufsize == 0)
+ return uv_translate_sys_error(GetLastError());
+
+ *size = bufsize - 1;
+ return 0;
+}