Skip to content

Commit

Permalink
src: cleanup uv_fs_t regardless of success or not
Browse files Browse the repository at this point in the history
PR-URL: nodejs#38996
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
  • Loading branch information
legendecas authored and foxxyz committed Oct 18, 2021
1 parent a337c07 commit eb4d7f5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ int WriteFileSync(v8::Isolate* isolate,

int ReadFileSync(std::string* result, const char* path) {
uv_fs_t req;
auto defer_req_cleanup = OnScopeLeave([&req]() {
uv_fs_req_cleanup(&req);
});

uv_file file = uv_fs_open(nullptr, &req, path, O_RDONLY, 0, nullptr);
if (req.result < 0) {
// req will be cleaned up by scope leave.
return req.result;
}
uv_fs_req_cleanup(&req);
Expand All @@ -243,7 +248,7 @@ int ReadFileSync(std::string* result, const char* path) {
const int r =
uv_fs_read(nullptr, &req, file, &buf, 1, result->length(), nullptr);
if (req.result < 0) {
uv_fs_req_cleanup(&req);
// req will be cleaned up by scope leave.
return req.result;
}
uv_fs_req_cleanup(&req);
Expand Down

0 comments on commit eb4d7f5

Please sign in to comment.