Skip to content

Commit

Permalink
Merge pull request #2033 from 0intro/coverity-deadlocks-20230920
Browse files Browse the repository at this point in the history
Fix deadlocks reported by Coverity
  • Loading branch information
jan-cerny authored Sep 25, 2023
2 parents 3cca20f + dd51ba5 commit 1d5dfe1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/OVAL/probes/SEAP/seap-packetq.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ int SEAP_packetq_put(SEAP_packetq_t *queue, SEAP_packet_t *packet)
queue->last = queue->first;
} else {
if (queue->last == NULL) {
return -1; /* XXX: unlock */
pthread_mutex_unlock(&queue->lock);
return -1;
}
if (queue->last->next != NULL) {
pthread_mutex_unlock(&queue->lock);
return -1;
}

Expand Down
5 changes: 5 additions & 0 deletions src/OVAL/probes/probe/icache.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const char* thread_name = "icache_worker";

while(pthread_cond_wait(&cache->queue_notempty, &cache->queue_mutex) == 0) {
if (cache->queue_cnt <= 0) {
pthread_mutex_unlock(&cache->queue_mutex);
return NULL;
}
do {
Expand All @@ -234,6 +235,7 @@ const char* thread_name = "icache_worker";
if (cache->queue_cnt == 0 ?
cache->queue_end != cache->queue_beg :
cache->queue_end == cache->queue_beg) {
pthread_mutex_unlock(&cache->queue_mutex);
return NULL;
}

Expand Down Expand Up @@ -412,6 +414,7 @@ int probe_icache_add(probe_icache_t *cache, SEXP_t *cobj, SEXP_t *item)
if (pthread_cond_signal(&cache->queue_notempty) != 0) {
dE("An error ocured while signaling the `notempty' condition: %u, %s",
errno, strerror(errno));
pthread_mutex_unlock(&cache->queue_mutex);
return (-1);
}

Expand Down Expand Up @@ -442,6 +445,7 @@ int probe_icache_nop(probe_icache_t *cache)
if (pthread_cond_init(&cond, NULL) != 0) {
dE("Can't initialize icache queue condition variable (NOP): %u, %s",
errno, strerror(errno));
pthread_mutex_unlock(&cache->queue_mutex);
return (-1);
}

Expand All @@ -463,6 +467,7 @@ int probe_icache_nop(probe_icache_t *cache)
errno, strerror(errno));

pthread_cond_destroy(&cond);
pthread_mutex_unlock(&cache->queue_mutex);
return (-1);
}

Expand Down

0 comments on commit 1d5dfe1

Please sign in to comment.