Skip to content

Commit 6641124

Browse files
author
Razvan Becheriu
committed
[#3708] fixed closedir
1 parent c892df7 commit 6641124

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib/util/filesystem.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ TemporaryDirectory::~TemporaryDirectory() {
195195
return;
196196
}
197197

198+
std::unique_ptr<DIR, void(*)(DIR*)> defer(dir, [](DIR* d) { closedir(d); });
199+
198200
struct dirent *i;
199201
string filepath;
200202
while ((i = readdir(dir))) {
@@ -205,7 +207,7 @@ TemporaryDirectory::~TemporaryDirectory() {
205207
filepath = dir_name_ + '/' + i->d_name;
206208
remove(filepath.c_str());
207209
}
208-
closedir(dir);
210+
209211
rmdir(dir_name_.c_str());
210212
}
211213

0 commit comments

Comments
 (0)