Skip to content

Commit

Permalink
fixup! fs: check closing_ in FileHandle::Close
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jul 20, 2021
1 parent 71343ea commit e673cc7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ FileHandle::TransferData::TransferData(int fd) : fd_(fd) {}
FileHandle::TransferData::~TransferData() {
if (fd_ > 0) {
uv_fs_t close_req;
CHECK_NE(fd_, -1);
CHECK_EQ(0, uv_fs_close(nullptr, &close_req, fd_, nullptr));
uv_fs_req_cleanup(&close_req);
}
Expand All @@ -239,6 +240,7 @@ BaseObjectPtr<BaseObject> FileHandle::TransferData::Deserialize(
inline void FileHandle::Close() {
if (closed_ || closing_) return;
uv_fs_t req;
CHECK_NE(fd_, -1);
int ret = uv_fs_close(env()->event_loop(), &req, fd_, nullptr);
uv_fs_req_cleanup(&req);

Expand Down Expand Up @@ -384,6 +386,7 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
close->Resolve();
}
}};
CHECK_NE(fd_, -1);
int ret = req->Dispatch(uv_fs_close, fd_, AfterClose);
if (ret < 0) {
req->Reject(UVException(isolate, ret, "close"));
Expand Down Expand Up @@ -555,8 +558,11 @@ ShutdownWrap* FileHandle::CreateShutdownWrap(Local<Object> object) {
}

int FileHandle::DoShutdown(ShutdownWrap* req_wrap) {
if (closing_ || closed_)
return 0;
FileHandleCloseWrap* wrap = static_cast<FileHandleCloseWrap*>(req_wrap);
closing_ = true;
CHECK_NE(fd_, -1);
wrap->Dispatch(uv_fs_close, fd_, uv_fs_callback_t{[](uv_fs_t* req) {
FileHandleCloseWrap* wrap = static_cast<FileHandleCloseWrap*>(
FileHandleCloseWrap::from_req(req));
Expand Down

0 comments on commit e673cc7

Please sign in to comment.