detect/loader: add threading coverity warning

lock_acquire: Calling pthread_mutex_lock acquires lock ThreadVars_.ctrl_mutex.
725        SCCtrlMutexLock(th_v->ctrl_mutex);

CID 1554214: (#1 of 1): Indefinite wait (BAD_CHECK_OF_WAIT_COND)
dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock ThreadVars_.ctrl_mutex. This can cause a deadlock if the notification happens before the lock is acquired.
      Acquire the lock, then check the wait condition in a loop, without releasing with the lock before the wait. This will prevent deadlocks and failed conditions from spurious wakeups.
pull/13518/head
Victor Julien 1 year ago committed by Victor Julien
parent 5aaef39c8c
commit 65ff3dfa88

@ -717,13 +717,22 @@ static TmEcode DetectLoader(ThreadVars *th_v, void *thread_data)
SCMutexUnlock(&loader->m);
if (TmThreadsCheckFlag(th_v, THV_KILL)) {
break;
}
/* just wait until someone wakes us up */
SCCtrlMutexLock(th_v->ctrl_mutex);
SCCtrlCondWait(th_v->ctrl_cond, th_v->ctrl_mutex);
int rc = 0;
while (rc == 0) {
if (TmThreadsCheckFlag(th_v, THV_KILL)) {
run = false;
break;
}
SCMutexLock(&loader->m);
bool has_work = loader->task_list.tqh_first != NULL;
SCMutexUnlock(&loader->m);
if (has_work)
break;
rc = SCCtrlCondWait(th_v->ctrl_cond, th_v->ctrl_mutex);
}
SCCtrlMutexUnlock(th_v->ctrl_mutex);
SCLogDebug("woke up...");

Loading…
Cancel
Save