From a67d2a800334d99d3bc7e8deb484cd3e1918c348 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Tue, 13 Oct 2026 07:52:12 -0300 Subject: [PATCH] src: release uv_fs_t in permission WildcardIfDir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call uv_fs_req_cleanup() before returning for directories, otherwise the path buffer allocated by uv_fs_stat() leaks on Windows. Signed-off-by: RafaelGSS PR-URL: https://github.com/nodejs/node/pull/66555 Reviewed-By: Ulises Gascón --- src/permission/fs_permission.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/permission/fs_permission.cc b/src/permission/fs_permission.cc index fd3b159f579..6293844476f 100644 --- a/src/permission/fs_permission.cc +++ b/src/permission/fs_permission.cc @@ -16,17 +16,17 @@ namespace { std::string WildcardIfDir(const std::string& res) noexcept { uv_fs_t req; int rc = uv_fs_stat(nullptr, &req, res.c_str(), nullptr); - if (rc == 0) { - const uv_stat_t* const s = static_cast(req.ptr); - if ((s->st_mode & S_IFMT) == S_IFDIR) { - // add wildcard when directory - if (res.back() == node::kPathSeparator) { - return res + "*"; - } - return res + node::kPathSeparator + "*"; - } - } + const bool is_dir = + rc == 0 && + (static_cast(req.ptr)->st_mode & S_IFMT) == S_IFDIR; uv_fs_req_cleanup(&req); + if (is_dir) { + // add wildcard when directory + if (res.back() == node::kPathSeparator) { + return res + "*"; + } + return res + node::kPathSeparator + "*"; + } return res; }