Skip to content

Commit e723b47

Browse files
authored
Merge pull request #6668 from jeniawhite/evgb-NSFSDTOR
Making sure to close FD and DIR on DTOR
2 parents b700dae + 0628bd5 commit e723b47

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/native/fs/fs_napi.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,10 @@ struct FileWrap : public Napi::ObjectWrap<FileWrap>
722722
~FileWrap()
723723
{
724724
if (_fd) {
725-
PANIC("FS::FileWrap::dtor: file not closed " << DVAL(_path) << DVAL(_fd));
725+
LOG("FS::FileWrap::dtor: file not closed " << DVAL(_path) << DVAL(_fd));
726+
int r = ::close(_fd);
727+
if (r) LOG("FS::FileWrap::dtor: file close failed " << DVAL(_path) << DVAL(_fd) << DVAL(r));
728+
_fd = 0;
726729
}
727730
}
728731
Napi::Value close(const Napi::CallbackInfo& info);
@@ -1144,7 +1147,10 @@ struct DirWrap : public Napi::ObjectWrap<DirWrap>
11441147
~DirWrap()
11451148
{
11461149
if (_dir) {
1147-
PANIC("FS::DirWrap::dtor: dir not closed " << DVAL(_path) << DVAL(_dir));
1150+
LOG("FS::DirWrap::dtor: dir not closed " << DVAL(_path) << DVAL(_dir));
1151+
int r = closedir(_dir);
1152+
if (r) LOG("FS::DirWrap::dtor: dir close failed " << DVAL(_path) << DVAL(_dir) << DVAL(r));
1153+
_dir = 0;
11481154
}
11491155
}
11501156
Napi::Value close(const Napi::CallbackInfo& info);

0 commit comments

Comments
 (0)