From 8221f9b305c09205be575d8d34a5c493ba03d392 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Fri, 23 Sep 2016 13:18:06 -0700 Subject: [PATCH] win: fix leaky fs request buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a large number of buffers (>4) is passed into `uv_fs_read()` or `uv_fs_write()`, a new buffer is dynamically allocated to hold a copy of the request data. This change adds code in `uv_fs_req_cleanup()` to free that buffer if it was allocated. Refs: https://github.com/nodejs/node/issues/7191 Fixes: https://github.com/libuv/libuv/issues/1069 PR-URL: https://github.com/libuv/libuv/pull/1070 Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé --- src/win/fs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/win/fs.c b/src/win/fs.c index 6a4157bf..f1711acf 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -230,6 +230,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; + memset(&req->fs, 0, sizeof(req->fs)); } @@ -1893,9 +1894,13 @@ void uv_fs_req_cleanup(uv_fs_t* req) { uv__free(req->ptr); } + if (req->fs.info.bufs != req->fs.info.bufsml) + uv__free(req->fs.info.bufs); + req->path = NULL; req->file.pathw = NULL; req->fs.info.new_pathw = NULL; + req->fs.info.bufs = NULL; req->ptr = NULL; req->flags |= UV_FS_CLEANEDUP;