core: fix wrong logic in _osmo_it_q_dequeue()
If the given queue is empty, queue->list.next points to &queue->list.
Current implementation would call llist_del() on the queue's llist_head,
decrement queue->current_length (which will be 0), and return a pointer
to &queue->list to the caller. This is completely wrong.
- Use the existing item_dequeue(), which does exactly what we need.
- Do not decrement the current_length if nothing was dequeued.
- Uncomment code in the unit test, we should not crash anymore.
Change-Id: I63094df73b166b549616c869ad908e9f4f7d46d1
Fixes: CID#336557
diff --git a/src/core/it_q.c b/src/core/it_q.c
index a3ff420..810dc90 100644
--- a/src/core/it_q.c
+++ b/src/core/it_q.c
@@ -245,7 +245,7 @@
/*! Thread-safe de-queue from an inter-thread message queue.
* \param[in] queue Inter-thread queue from which to dequeue
- * \returns dequeued message buffer; NULL if none available
+ * \returns llist_head of dequeued message; NULL if none available
*/
struct llist_head *_osmo_it_q_dequeue(struct osmo_it_q *queue)
{
@@ -254,12 +254,9 @@
pthread_mutex_lock(&queue->mutex);
- if (llist_empty(&queue->list))
- l = NULL;
- l = queue->list.next;
- OSMO_ASSERT(l);
- llist_del(l);
- queue->current_length--;
+ l = item_dequeue(&queue->list);
+ if (l != NULL)
+ queue->current_length--;
pthread_mutex_unlock(&queue->mutex);