Address Coverity mutex issues
Coverity has generated a number of 'Data race condition' and 'Double lock' false positives. A lot of these seem to be caused by the NULL guard in tc_mutex_unlock() not being paired with a NULL guard in tc_mutex_lock(). This PR adds a NULL guard to tc_mutex_lock(). It should be noted, that on Linux at least, passing NULL to tc_mutex_lock() causes a segfault. We clearly aren't doing this at the moment, or we'd know about it. A log message is generated if a NULL call is made, rather than failing silently.
This commit is contained in:
+10
-3
@@ -33,6 +33,7 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#endif
|
#endif
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
|
#include "log.h"
|
||||||
#include "thread_calls.h"
|
#include "thread_calls.h"
|
||||||
#include "os_calls.h"
|
#include "os_calls.h"
|
||||||
|
|
||||||
@@ -136,11 +137,17 @@ tc_mutex_lock(tbus mutex)
|
|||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
WaitForSingleObject((HANDLE)mutex, INFINITE);
|
WaitForSingleObject((HANDLE)mutex, INFINITE);
|
||||||
return 0;
|
|
||||||
#else
|
#else
|
||||||
pthread_mutex_lock((pthread_mutex_t *)mutex);
|
if (mutex != 0)
|
||||||
return 0;
|
{
|
||||||
|
pthread_mutex_lock((pthread_mutex_t *)mutex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG(LOG_LEVEL_ERROR, "Attempt made to lock NULL mutex");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user