Merge pull request #3902 from akallabeth/file_leak_fix

Fixed a memory leak and bad free.
This commit is contained in:
Norbert Federa 2017-04-11 12:50:15 +02:00 committed by GitHub
commit 0d19e7bb2f

View File

@ -475,8 +475,10 @@ BOOL WINAPI GetFileAttributesExA(LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfo
WIN32_FIND_DATAA findFileData;
HANDLE hFind;
if ((hFind = FindFirstFileA(lpFileName, &findFileData) != INVALID_HANDLE_VALUE))
FindClose(hFind);
if ((hFind = FindFirstFileA(lpFileName, &findFileData)) == INVALID_HANDLE_VALUE)
return FALSE;
FindClose(hFind);
fd->dwFileAttributes = findFileData.dwFileAttributes;
fd->ftCreationTime = findFileData.ftCreationTime;
@ -858,6 +860,7 @@ HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
if (ConvertFromUnicode(CP_UTF8, 0, lpFileName, -1, &utfFileName, 0, NULL, NULL) <= 0)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
free(fd);
return INVALID_HANDLE_VALUE;
}
@ -1021,22 +1024,19 @@ BOOL FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)
BOOL FindClose(HANDLE hFindFile)
{
WIN32_FILE_SEARCH* pFileSearch;
pFileSearch = (WIN32_FILE_SEARCH*) hFindFile;
WIN32_FILE_SEARCH* pFileSearch = (WIN32_FILE_SEARCH*) hFindFile;
if (pFileSearch)
{
free(pFileSearch->lpPath);
free(pFileSearch->lpPattern);
if (!pFileSearch || (pFileSearch == INVALID_HANDLE_VALUE))
return FALSE;
if (pFileSearch->pDir)
closedir(pFileSearch->pDir);
free(pFileSearch->lpPath);
free(pFileSearch->lpPattern);
free(pFileSearch);
return TRUE;
}
if (pFileSearch->pDir)
closedir(pFileSearch->pDir);
return FALSE;
free(pFileSearch);
return TRUE;
}
BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)