From a384ff68a165bc8a46bc132366a3c56ce53562d6 Mon Sep 17 00:00:00 2001 From: JesterHodl Date: Wed, 23 Oct 2024 00:34:54 +0200 Subject: [PATCH] Fix bugs in datum_queue_free 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? --- src/datum_queue.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/datum_queue.c b/src/datum_queue.c index 14837d5..b7e988b 100644 --- a/src/datum_queue.c +++ b/src/datum_queue.c @@ -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]);