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: #38996
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
legendecas authored and danielleadams committed Jun 21, 2021
1 parent 5e9175f commit 284d9c6
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 284d9c6

Please sign in to comment.