From fd5406282d0767ddb7609de4790368e168b56aba Mon Sep 17 00:00:00 2001 From: Jimmy Thrasher Date: Sat, 5 Apr 2014 17:59:09 -0400 Subject: [PATCH] Fix crash caused by attempting to close a nonexistent DIR* --- src/file.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)