diff --git a/compat/mingw.c b/compat/mingw.c index 36899908ee..e6f331a581 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; }