From 1167ec3f476e1886606ca76bd153708aead0d397 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 21 Feb 2018 11:30:37 -0500 Subject: [PATCH] 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 --- src/unix/fs.c | 5 +++++ src/win/fs.c | 1 + 2 files changed, 6 insertions(+) diff --git a/src/unix/fs.c b/src/unix/fs.c index bd0d0bea..92e2d255 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -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; diff --git a/src/win/fs.c b/src/win/fs.c index 097b00e0..6e0bdc7b 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -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)); }