Skip to content

Commit

Permalink
Fix bugs in datum_queue_free
Browse files Browse the repository at this point in the history
1. q->buffer[1] doesn't seem to be free()'d

2. q->buffer[0] is duplicated, you probably meant to zero out buffer[1]

3. shouldn't the unlocking order be reverse of locking order to prevent deadlocks?
  • Loading branch information
jesterhodl committed Oct 22, 2024
1 parent 62d92d0 commit a384ff6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/datum_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ int datum_queue_free(DATUM_QUEUE *q) {
if (q->buffer[0]) {
free(q->buffer[0]);
}
if (q->buffer[1]) {
free(q->buffer[1]);
}

q->initialized = false;
q->buffer[0] = 0;
q->buffer[0] = 0;
q->buffer[1] = 0;

pthread_rwlock_unlock(&q->active_buffer_rwlock);
pthread_rwlock_unlock(&q->buffer_rwlock[0]);
pthread_rwlock_unlock(&q->buffer_rwlock[1]);
pthread_rwlock_unlock(&q->buffer_rwlock[0]);
pthread_rwlock_unlock(&q->active_buffer_rwlock);

pthread_rwlock_destroy(&q->active_buffer_rwlock);
pthread_rwlock_destroy(&q->buffer_rwlock[0]);
Expand Down

0 comments on commit a384ff6

Please sign in to comment.