| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -223,8 +223,13 @@ int WriteFileSync(v8::Isolate* isolate, | |||
| 223 | 223 | ||
| 224 | 224 | int ReadFileSync(std::string* result, const char* path) { | |
| 225 | 225 | uv_fs_t req; | |
| 226 | + auto defer_req_cleanup = OnScopeLeave([&req]() { | ||
| 227 | + uv_fs_req_cleanup(&req); | ||
| 228 | + }); | ||
| 229 | + | ||
| 226 | 230 | uv_file file = uv_fs_open(nullptr, &req, path, O_RDONLY, 0, nullptr); | |
| 227 | 231 | if (req.result < 0) { | |
| 232 | + // req will be cleaned up by scope leave. | ||
| 228 | 233 | return req.result; | |
| 229 | 234 | } | |
| 230 | 235 | uv_fs_req_cleanup(&req); | |
@@ -243,7 +248,7 @@ int ReadFileSync(std::string* result, const char* path) { | |||
| 243 | 248 | const int r = | |
| 244 | 249 | uv_fs_read(nullptr, &req, file, &buf, 1, result->length(), nullptr); | |
| 245 | 250 | if (req.result < 0) { | |
| 246 | - uv_fs_req_cleanup(&req); | ||
| 251 | + // req will be cleaned up by scope leave. | ||
| 247 | 252 | return req.result; | |
| 248 | 253 | } | |
| 249 | 254 | uv_fs_req_cleanup(&req); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments