Skip to content

Commit 7d7dc16

Browse files
gireeshpunathiltargos
authored andcommitted
src: unique_ptrs in few lambdas
Few lambdas in src/node_file.cc uses conventional pointers, turn those into unique_ptr semantics PR-URL: #23124 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent e791abe commit 7d7dc16

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/node_file.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ inline void FileHandle::Close() {
163163
// Do not unref this
164164
env()->SetImmediate([](Environment* env, void* data) {
165165
char msg[70];
166-
err_detail* detail = static_cast<err_detail*>(data);
166+
std::unique_ptr<err_detail> detail(static_cast<err_detail*>(data));
167167
snprintf(msg, arraysize(msg),
168168
"Closing file descriptor %d on garbage collection failed",
169169
detail->fd);
@@ -173,7 +173,6 @@ inline void FileHandle::Close() {
173173
// down the process is the only reasonable thing we can do here.
174174
HandleScope handle_scope(env->isolate());
175175
env->ThrowUVException(detail->ret, "close", msg);
176-
delete detail;
177176
}, detail);
178177
return;
179178
}
@@ -182,11 +181,10 @@ inline void FileHandle::Close() {
182181
// to notify that the file descriptor was gc'd. We want to be noisy about
183182
// this because not explicitly closing the FileHandle is a bug.
184183
env()->SetUnrefImmediate([](Environment* env, void* data) {
185-
err_detail* detail = static_cast<err_detail*>(data);
184+
std::unique_ptr<err_detail> detail(static_cast<err_detail*>(data));
186185
ProcessEmitWarning(env,
187186
"Closing file descriptor %d on garbage collection",
188187
detail->fd);
189-
delete detail;
190188
}, detail);
191189
}
192190

@@ -234,7 +232,7 @@ inline MaybeLocal<Promise> FileHandle::ClosePromise() {
234232
closing_ = true;
235233
CloseReq* req = new CloseReq(env(), promise, object());
236234
auto AfterClose = uv_fs_callback_t{[](uv_fs_t* req) {
237-
CloseReq* close = CloseReq::from_req(req);
235+
std::unique_ptr<CloseReq> close(CloseReq::from_req(req));
238236
CHECK_NOT_NULL(close);
239237
close->file_handle()->AfterClose();
240238
Isolate* isolate = close->env()->isolate();
@@ -243,7 +241,6 @@ inline MaybeLocal<Promise> FileHandle::ClosePromise() {
243241
} else {
244242
close->Resolve();
245243
}
246-
delete close;
247244
}};
248245
int ret = req->Dispatch(uv_fs_close, fd_, AfterClose);
249246
if (ret < 0) {

0 commit comments

Comments
 (0)