The InitMemoryMgr method creates the mutex without taking ownership:
CommBuffer->ghMutex = CreateMutex(&sa, FALSE, MUTEX_NAME);
Then, later in the function, it releases ownership in multiple places although it does not have it:
if (CommBuffer->ghEvent == NULL)
{
if(errco == 0)
errco = GENERALERRORCODE;
free((char*)lpSharedMemoryName);
ReleaseMutex(CommBuffer->ghMutex);
...
if(CommBuffer->ghMapFile == NULL || CommBuffer->ghMapFile == INVALID_HANDLE_VALUE)
{
if(errco == 0)
errco = GENERALERRORCODE;
free((char*)lpSharedMemoryName);
ReleaseMutex(CommBuffer->ghMutex);
...
if (CommBuffer->gpBuf == NULL)
{
if(errco == 0)
errco = GENERALERRORCODE;
free((char*)lpSharedMemoryName);
ReleaseMutex(CommBuffer->ghMutex);
...
ReleaseMutex(CommBuffer->ghMutex);
free((char*)lpSharedMemoryName);
return SUCCESS;
The Join method does the same thing.