diff --git a/compat/mingw.c b/compat/mingw.c index dbc746bff3..9945ce7b97 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -243,8 +243,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; }