Skip to content

Commit 67fbccc

Browse files
committed
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.
1 parent fa9cc88 commit 67fbccc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

common/thread_calls.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <semaphore.h>
3434
#endif
3535
#include "arch.h"
36+
#include "log.h"
3637
#include "thread_calls.h"
3738
#include "os_calls.h"
3839

@@ -136,11 +137,17 @@ tc_mutex_lock(tbus mutex)
136137
{
137138
#if defined(_WIN32)
138139
WaitForSingleObject((HANDLE)mutex, INFINITE);
139-
return 0;
140140
#else
141-
pthread_mutex_lock((pthread_mutex_t *)mutex);
142-
return 0;
141+
if (mutex != 0)
142+
{
143+
pthread_mutex_lock((pthread_mutex_t *)mutex);
144+
}
145+
else
146+
{
147+
LOG(LOG_LEVEL_ERROR, "Attempt made to lock NULL mutex");
148+
}
143149
#endif
150+
return 0;
144151
}
145152

146153
/*****************************************************************************/

0 commit comments

Comments
 (0)