unix,win: ensure req->bufs is freed

This commit ensures that req->bufs (req->fs.info.bufs on Windows)
is initialized to NULL in INIT and freed, if necessary, in
uv_fs_req_cleanup().

Refs: https://github.com/libuv/libuv/pull/1751#discussion_r169645330
PR-URL: https://github.com/libuv/libuv/pull/1752
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
cjihrig 2018-02-21 11:30:37 -05:00
parent e485d28674
commit 1167ec3f47
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
2 changed files with 6 additions and 0 deletions

View File

@ -75,6 +75,7 @@
req->loop = loop; \
req->path = NULL; \
req->new_path = NULL; \
req->bufs = NULL; \
req->cb = cb; \
} \
while (0)
@ -1485,6 +1486,10 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
uv__fs_scandir_cleanup(req);
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
if (req->ptr != &req->statbuf)
uv__free(req->ptr);
req->ptr = NULL;

View File

@ -245,6 +245,7 @@ INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req,
req->ptr = NULL;
req->path = NULL;
req->cb = cb;
req->fs.info.bufs = NULL;
memset(&req->fs, 0, sizeof(req->fs));
}