From 8b37dbb75c2b4d5b0dcf85a2ff417fda89e4fd62 Mon Sep 17 00:00:00 2001
From: Rein Klazes <rklazes@xs4all.nl>
Date: Mon, 9 Apr 2001 18:29:17 +0000
Subject: [PATCH] When calling CreateMutex() handle the case when the mutex is
 already created in another process.

---
 dlls/user/ddeml.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/dlls/user/ddeml.c b/dlls/user/ddeml.c
index 48597d5c19a..44692106140 100644
--- a/dlls/user/ddeml.c
+++ b/dlls/user/ddeml.c
@@ -379,14 +379,15 @@ DWORD IncrementInstanceId( DDE_HANDLE_ENTRY *this_instance)
 		s_attrib.bInheritHandle = TRUE;
 		s_attrib.lpSecurityDescriptor = NULL;
 		s_attrib.nLength = sizeof(s_attrib);
-		inst_count_mutex = CreateMutexA(&s_attrib,1,DDEInstanceAccess); /* 1st time through */
-	} else {
+		inst_count_mutex = CreateMutexA(&s_attrib,0,DDEInstanceAccess); /* 1st time through */
+	} 
+        if ( inst_count_mutex )
+        {
         	if ( !WaitForMutex(inst_count_mutex) )
         	{
                 	return DMLERR_SYS_ERROR;
         	}
-	}
-	if ( !inst_count_mutex )
+        } else
 	{
 		ERR("CreateMutex failed - inst_count %li\n",GetLastError());
 		Release_reserved_mutex (handle_mutex,"handle_mutex",0,1,this_instance);
@@ -606,23 +607,22 @@ UINT WINAPI DdeInitializeW( LPDWORD pidInst, PFNCALLBACK pfnCallback,
         TRACE("new instance, callback %p flags %lX\n",pfnCallback,afCmd);
         if ( DDE_Max_Assigned_Instance == 0 )
         {
-                /*  Nothing has been initialised - exit now ! can return TRUE since effect is the same */
-	/*  Need to set up Mutex in case it is not already present */
-	s_att->bInheritHandle = TRUE;
-	s_att->lpSecurityDescriptor = NULL;
-	s_att->nLength = sizeof(s_att);
-	handle_mutex = CreateMutexA(s_att,1,DDEHandleAccess);
-	if ( !handle_mutex ) {
-		ERR("CreateMutex failed - handle list  %li\n",GetLastError());
-		HeapFree(GetProcessHeap(), 0, this_instance);
-		return DMLERR_SYS_ERROR;
-	}
-    } else {
-	if ( !WaitForMutex(handle_mutex) )
-	{
-		return DMLERR_SYS_ERROR;
-	}
-    }
+            /*  Nothing has been initialised - exit now ! can return TRUE since effect is the same */
+            /*  Need to set up Mutex in case it is not already present */
+            s_att->bInheritHandle = TRUE;
+            s_att->lpSecurityDescriptor = NULL;
+            s_att->nLength = sizeof(s_att);
+            handle_mutex = CreateMutexA(s_att,0,DDEHandleAccess);
+            if ( !handle_mutex ) {
+                    ERR("CreateMutex failed - handle list  %li\n",GetLastError());
+                    HeapFree(GetProcessHeap(), 0, this_instance);
+                    return DMLERR_SYS_ERROR;
+            }
+        }
+        if ( !WaitForMutex(handle_mutex) )
+        {
+                return DMLERR_SYS_ERROR;
+        }
 
 	TRACE("Handle Mutex created/reserved\n");
         if (DDE_Handle_Table_Base == NULL ) 
-- 
GitLab