From 75fc82c965611d8f71f93131008771f2252d18fe Mon Sep 17 00:00:00 2001 From: Aric Cyr Date: Sat, 4 Mar 2006 03:43:04 +0900 Subject: [PATCH] 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 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dlls/dplayx/dplayx_global.c b/dlls/dplayx/dplayx_global.c index 5255f71f1b0..723b7e538a2 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 -- 2.11.4.GIT