src: release uv_fs_t in permission WildcardIfDir

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 <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66555
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
This commit is contained in:
Rafael Gonzaga authored and Antoine du Hamel committed 2026-11-11 17:28:09 +01:00
1 parent d07ecf988d
commit 912fd55a04
1 file changed
+10 -10
+10 -10
View File
@@ -19,17 +19,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<const uv_stat_t*>(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<const uv_stat_t*>(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;
}