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

Alexandre Julliard julliard at winehq.org
Fri Apr 22 12:27:42 CDT 2011


Module: wine
Branch: master
Commit: 2e61684c5108eca65da451a473922c3f7fd4a891
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2e61684c5108eca65da451a473922c3f7fd4a891

Author: Thomas Mullaly <tmullaly at codeweavers.com>
Date:   Tue Apr 19 15:41:20 2011 -0400

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

---

 dlls/wininet/urlcache.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/dlls/wininet/urlcache.c b/dlls/wininet/urlcache.c
index 4d074ed..9cae3d7 100644
--- a/dlls/wininet/urlcache.c
+++ b/dlls/wininet/urlcache.c
@@ -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;
 }
 




More information about the wine-cvs mailing list