diff --git a/include/uv-private/uv-win.h b/include/uv-private/uv-win.h index cd15705e..30962c36 100644 --- a/include/uv-private/uv-win.h +++ b/include/uv-private/uv-win.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "tree.h" @@ -246,6 +247,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s); #define UV_FS_PRIVATE_FIELDS \ int flags; \ + struct _stat stat; \ void* arg0; \ union { \ struct { \ diff --git a/src/win/fs.c b/src/win/fs.c index 15f92961..cd647181 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -234,17 +234,11 @@ done: void fs__stat(uv_fs_t* req, const char* path) { int result; - req->ptr = malloc(sizeof(struct _stat)); - if (!req->ptr) { - uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); - } - - result = _stat(path, (struct _stat*)req->ptr); + result = _stat(path, &req->stat); if (result == -1) { - free(req->ptr); req->ptr = NULL; } else { - req->flags |= UV_FS_FREE_PTR; + req->ptr = &req->stat; } SET_REQ_RESULT(req, result); @@ -254,17 +248,11 @@ void fs__stat(uv_fs_t* req, const char* path) { void fs__fstat(uv_fs_t* req, uv_file file) { int result; - req->ptr = malloc(sizeof(struct _stat)); - if (!req->ptr) { - uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); - } - - result = _fstat(file, (struct _stat*)req->ptr); + result = _fstat(file, &req->stat); if (result == -1) { - free(req->ptr); req->ptr = NULL; } else { - req->flags |= UV_FS_FREE_PTR; + req->ptr = &req->stat; } SET_REQ_RESULT(req, result); @@ -807,9 +795,10 @@ void uv_fs_req_cleanup(uv_fs_t* req) { if (req->flags & UV_FS_FREE_PTR && req->ptr) { free(req->ptr); - req->ptr = NULL; } + req->ptr = NULL; + if (req->flags & UV_FS_ASYNC_QUEUED) { uv_unref(loop); } diff --git a/test/test-fs.c b/test/test-fs.c index 4d72abd6..44cf6db7 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -486,10 +486,10 @@ TEST_IMPL(fs_async_dir) { TEST_IMPL(fs_async_sendfile) { int f, r; - - /* Setup. */ struct stat s1, s2; + /* Setup. */ + uv_init(); unlink("test_file"); unlink("test_file2"); @@ -509,7 +509,6 @@ TEST_IMPL(fs_async_sendfile) { ASSERT(r == 0); /* Test starts here. */ - uv_init(); loop = uv_default_loop(); r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);