Fix crash caused by attempting to close a nonexistent DIR*

This commit is contained in:
Jimmy Thrasher 2014-04-05 17:59:09 -04:00
parent c4e694fb7b
commit fd5406282d

View File

@ -275,7 +275,10 @@ std::vector<String> list_files(const String& prefix,
{ {
kak_assert(dirname.empty() or dirname.back() == '/'); kak_assert(dirname.empty() or dirname.back() == '/');
DIR* dir = opendir(dirname.empty() ? "./" : dirname.c_str()); 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<String> result; std::vector<String> result;
if (not dir) if (not dir)