Module: wine Branch: refs/heads/master Commit: 75fc82c965611d8f71f93131008771f2252d18fe URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=75fc82c965611d8f71f93131...
Author: Aric Cyr aric.cyr@gmail.com Date: Sat Mar 4 03:43:04 2006 +0900
dplayx: Fix semaphore deadlock.
- Make sure to release the dplayx semaphore in for error cases as well. - Prevent race condition between creation of the semaphore and grabbing of the lock by creating the semaphore in the locked state instead of unlocked.
---
dlls/dplayx/dplayx_global.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/dlls/dplayx/dplayx_global.c b/dlls/dplayx/dplayx_global.c index 5255f71..723b7e5 100644 --- a/dlls/dplayx/dplayx_global.c +++ b/dlls/dplayx/dplayx_global.c @@ -229,7 +229,7 @@ BOOL DPLAYX_ConstructData(void) s_attrib.lpSecurityDescriptor = NULL; s_attrib.nLength = sizeof(s_attrib);
- hDplayxSema = CreateSemaphoreA( &s_attrib, 1, 1, lpszDplayxSemaName ); + hDplayxSema = CreateSemaphoreA( &s_attrib, 0, 1, lpszDplayxSemaName );
/* First instance creates the semaphore. Others just use it */ if( GetLastError() == ERROR_SUCCESS ) @@ -242,6 +242,7 @@ BOOL DPLAYX_ConstructData(void) else if ( GetLastError() == ERROR_ALREADY_EXISTS ) { TRACE( "Found semaphore handle %p\n", hDplayxSema ); + DPLAYX_AquireSemaphore(); } else { @@ -251,8 +252,6 @@ BOOL DPLAYX_ConstructData(void)
SetLastError( ERROR_SUCCESS );
- DPLAYX_AquireSemaphore(); - hDplayxSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE, &s_attrib, PAGE_READWRITE | SEC_COMMIT, @@ -271,6 +270,7 @@ BOOL DPLAYX_ConstructData(void) else { ERR( ": unable to create shared memory (%ld)\n", GetLastError() ); + DPLAYX_ReleaseSemaphore(); return FALSE; }
@@ -282,6 +282,7 @@ BOOL DPLAYX_ConstructData(void) { ERR( ": unable to map static data into process memory space (%ld)\n", GetLastError() ); + DPLAYX_ReleaseSemaphore(); return FALSE; } else