Commit 2e61684c authored by Thomas Mullaly's avatar Thomas Mullaly Committed by Alexandre Julliard

wininet: Prevent a race condition which results in handles being leaked.

parent d0ea543f
......@@ -224,8 +224,12 @@ static DWORD URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
static const WCHAR wszIndex[] = {'i','n','d','e','x','.','d','a','t',0};
static const WCHAR wszMappingFormat[] = {'%','s','%','s','_','%','l','u',0};
if (pContainer->hMapping)
WaitForSingleObject(pContainer->hMutex, INFINITE);
if (pContainer->hMapping) {
ReleaseMutex(pContainer->hMutex);
return ERROR_SUCCESS;
}
strcpyW(wszFilePath, pContainer->path);
strcatW(wszFilePath, wszIndex);
......@@ -240,14 +244,10 @@ static DWORD URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
if (hFile == INVALID_HANDLE_VALUE)
{
TRACE("Could not open or create cache index file \"%s\"\n", debugstr_w(wszFilePath));
ReleaseMutex(pContainer->hMutex);
return GetLastError();
}
/* At this stage we need the mutex because we may be about to create the
* file.
*/
WaitForSingleObject(pContainer->hMutex, INFINITE);
dwFileSize = GetFileSize(hFile, NULL);
if (dwFileSize == INVALID_FILE_SIZE)
{
......@@ -420,8 +420,6 @@ static DWORD URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
}
ReleaseMutex(pContainer->hMutex);
wsprintfW(wszFilePath, wszMappingFormat, pContainer->path, wszIndex, dwFileSize);
URLCache_PathToObjectName(wszFilePath, '_');
pContainer->hMapping = OpenFileMappingW(FILE_MAP_WRITE, FALSE, wszFilePath);
......@@ -431,9 +429,12 @@ static DWORD URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
if (!pContainer->hMapping)
{
ERR("Couldn't create file mapping (error is %d)\n", GetLastError());
ReleaseMutex(pContainer->hMutex);
return GetLastError();
}
ReleaseMutex(pContainer->hMutex);
return ERROR_SUCCESS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment