Skip to content

Commit f873d87

Browse files
addaleaxMylesBorins
authored andcommitted
src: prefer OnScopeLeave over shared_ptr<void>
They do the same thing, but OnScopeLeave avoids an extra heap allocation and is more explicit about what it does. PR-URL: #32247 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
1 parent 569e555 commit f873d87

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/node_file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
821821
return;
822822
}
823823

824-
std::shared_ptr<void> defer_close(nullptr, [fd, loop] (...) {
824+
auto defer_close = OnScopeLeave([fd, loop]() {
825825
uv_fs_t close_req;
826826
CHECK_EQ(0, uv_fs_close(loop, &close_req, fd, nullptr));
827827
uv_fs_req_cleanup(&close_req);

src/node_native_module.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ MaybeLocal<String> NativeModuleLoader::LoadBuiltinModuleSource(Isolate* isolate,
202202
CHECK_GE(req.result, 0);
203203
uv_fs_req_cleanup(&req);
204204

205-
std::shared_ptr<void> defer_close(nullptr, [file](...) {
205+
auto defer_close = OnScopeLeave([file]() {
206206
uv_fs_t close_req;
207207
CHECK_EQ(0, uv_fs_close(nullptr, &close_req, file, nullptr));
208208
uv_fs_req_cleanup(&close_req);

0 commit comments

Comments
 (0)