@@ -163,7 +163,7 @@ inline void FileHandle::Close() {
163
163
// Do not unref this
164
164
env ()->SetImmediate ([](Environment* env, void * data) {
165
165
char msg[70 ];
166
- err_detail* detail = static_cast <err_detail*>(data);
166
+ std::unique_ptr< err_detail> detail ( static_cast <err_detail*>(data) );
167
167
snprintf (msg, arraysize (msg),
168
168
" Closing file descriptor %d on garbage collection failed" ,
169
169
detail->fd );
@@ -173,7 +173,6 @@ inline void FileHandle::Close() {
173
173
// down the process is the only reasonable thing we can do here.
174
174
HandleScope handle_scope (env->isolate ());
175
175
env->ThrowUVException (detail->ret , " close" , msg);
176
- delete detail;
177
176
}, detail);
178
177
return ;
179
178
}
@@ -182,11 +181,10 @@ inline void FileHandle::Close() {
182
181
// to notify that the file descriptor was gc'd. We want to be noisy about
183
182
// this because not explicitly closing the FileHandle is a bug.
184
183
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) );
186
185
ProcessEmitWarning (env,
187
186
" Closing file descriptor %d on garbage collection" ,
188
187
detail->fd );
189
- delete detail;
190
188
}, detail);
191
189
}
192
190
@@ -234,7 +232,7 @@ inline MaybeLocal<Promise> FileHandle::ClosePromise() {
234
232
closing_ = true ;
235
233
CloseReq* req = new CloseReq (env (), promise, object ());
236
234
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) );
238
236
CHECK_NOT_NULL (close );
239
237
close ->file_handle ()->AfterClose ();
240
238
Isolate* isolate = close ->env ()->isolate ();
@@ -243,7 +241,6 @@ inline MaybeLocal<Promise> FileHandle::ClosePromise() {
243
241
} else {
244
242
close ->Resolve ();
245
243
}
246
- delete close ;
247
244
}};
248
245
int ret = req->Dispatch (uv_fs_close, fd_, AfterClose);
249
246
if (ret < 0 ) {
0 commit comments