diff --git a/src/file.cc b/src/file.cc index 01fc36c5..653b2083 100644 --- a/src/file.cc +++ b/src/file.cc @@ -275,7 +275,10 @@ std::vector list_files(const String& prefix, { kak_assert(dirname.empty() or dirname.back() == '/'); DIR* dir = opendir(dirname.empty() ? "./" : dirname.c_str()); - auto closeDir = on_scope_end([=]{ closedir(dir); }); + auto closeDir = on_scope_end([=]{ + if (dir != NULL) + closedir(dir); + }); std::vector result; if (not dir)