diff --git a/compat/mingw.c b/compat/mingw.c index b8bad7baf3..79bac118ba 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -241,8 +241,11 @@ static int is_dir_empty(const wchar_t *wpath) while (!wcscmp(findbuf.cFileName, L".") || !wcscmp(findbuf.cFileName, L"..")) - if (!FindNextFileW(handle, &findbuf)) - return GetLastError() == ERROR_NO_MORE_FILES; + if (!FindNextFileW(handle, &findbuf)) { + DWORD err = GetLastError(); + FindClose(handle); + return err == ERROR_NO_MORE_FILES; + } FindClose(handle); return 0; }