2

Closed

Mutex released when not owned

description

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.
Closed Dec 9, 2010 at 4:58 AM by keithh
Since these lines of code are absolutely benign, I'm not inclined to remove them. I know logically they should never succeed but I'd rather leave them. These lines of code are also only executed during clean-up when a fatal error has occured.

comments