mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
src: cleanup uv_fs_t regardless of success or not
PR-URL: https://github.com/nodejs/node/pull/38996 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
1 parent
6f1862eab3
commit
43fe6c1d27
1 file changed
+6
-1
+6
-1
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user