Skip to content

Commit 43fe6c1

Browse files
legendecasrichardlau
authored andcommitted
src: cleanup uv_fs_t regardless of success or not
PR-URL: #38996 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 6f1862e commit 43fe6c1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/util.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,13 @@ int WriteFileSync(v8::Isolate* isolate,
223223

224224
int ReadFileSync(std::string* result, const char* path) {
225225
uv_fs_t req;
226+
auto defer_req_cleanup = OnScopeLeave([&req]() {
227+
uv_fs_req_cleanup(&req);
228+
});
229+
226230
uv_file file = uv_fs_open(nullptr, &req, path, O_RDONLY, 0, nullptr);
227231
if (req.result < 0) {
232+
// req will be cleaned up by scope leave.
228233
return req.result;
229234
}
230235
uv_fs_req_cleanup(&req);
@@ -243,7 +248,7 @@ int ReadFileSync(std::string* result, const char* path) {
243248
const int r =
244249
uv_fs_read(nullptr, &req, file, &buf, 1, result->length(), nullptr);
245250
if (req.result < 0) {
246-
uv_fs_req_cleanup(&req);
251+
// req will be cleaned up by scope leave.
247252
return req.result;
248253
}
249254
uv_fs_req_cleanup(&req);

0 commit comments

Comments
 (0)