Skip to content

Commit

Permalink
Address Coverity mutex issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matt335672 committed Feb 14, 2025
1 parent fa9cc88 commit 67fbccc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions common/thread_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <semaphore.h>
#endif
#include "arch.h"
#include "log.h"
#include "thread_calls.h"
#include "os_calls.h"

Expand Down Expand Up @@ -136,11 +137,17 @@ tc_mutex_lock(tbus mutex)
{
#if defined(_WIN32)
WaitForSingleObject((HANDLE)mutex, INFINITE);
return 0;
#else
pthread_mutex_lock((pthread_mutex_t *)mutex);
return 0;
if (mutex != 0)
{
pthread_mutex_lock((pthread_mutex_t *)mutex);
}
else
{
LOG(LOG_LEVEL_ERROR, "Attempt made to lock NULL mutex");
}
#endif
return 0;
}

/*****************************************************************************/
Expand Down

0 comments on commit 67fbccc

Please sign in to comment.