Skip to content

Commit a415654

Browse files
committed
fixup! fs: improve readFileSync with file descriptors
1 parent 28cf7ff commit a415654

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/node_file.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,6 @@ static void ReadFileUtf8(const FunctionCallbackInfo<Value>& args) {
25512551

25522552
uv_file file;
25532553
uv_fs_t req;
2554-
auto defer_req_cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
25552554

25562555
bool is_fd = args[0]->IsInt32();
25572556

@@ -2567,17 +2566,19 @@ static void ReadFileUtf8(const FunctionCallbackInfo<Value>& args) {
25672566
file = uv_fs_open(nullptr, &req, *path, flags, O_RDONLY, nullptr);
25682567
FS_SYNC_TRACE_END(open);
25692568
if (req.result < 0) {
2569+
uv_fs_req_cleanup(&req);
25702570
// req will be cleaned up by scope leave.
25712571
return env->ThrowUVException(req.result, "open", nullptr, path.out());
25722572
}
25732573
}
25742574

2575-
auto defer_close = OnScopeLeave([file, is_fd]() {
2575+
auto defer_close = OnScopeLeave([file, is_fd, &req]() {
25762576
if (!is_fd) {
2577-
uv_fs_t close_req;
2578-
CHECK_EQ(0, uv_fs_close(nullptr, &close_req, file, nullptr));
2579-
uv_fs_req_cleanup(&close_req);
2577+
FS_SYNC_TRACE_BEGIN(close);
2578+
CHECK_EQ(0, uv_fs_close(nullptr, &req, file, nullptr));
2579+
FS_SYNC_TRACE_END(close);
25802580
}
2581+
uv_fs_req_cleanup(&req);
25812582
});
25822583

25832584
std::string result{};

0 commit comments

Comments
 (0)