Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlegendecas <legendecas@gmail.com>2021-06-10 19:54:58 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-06-21 18:08:08 +0300
commit284d9c62285a3bcf78de007ef93970a6d30cc9c4 (patch)
tree764795a6b7d11e4244f6aa5c666f0b1c5b050ac1 /src
parent5e9175f1487a306c2b44d491a2192ed301d09dbc (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/util.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index 40ea25b8d2e..e181fdf568c 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -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);