Commit 1085bfd1 authored by Jean-Paul Saman's avatar Jean-Paul Saman

src/uasyncqueue.c: do not leak pthread resources

The UAsyncQueue leaked a mutex and conditional upon calling async_queue_free().
parent 15518786
...@@ -33,7 +33,6 @@ struct _UAsyncQueue { ...@@ -33,7 +33,6 @@ struct _UAsyncQueue {
UAsyncQueue *async_queue_new(void) UAsyncQueue *async_queue_new(void)
{ {
UAsyncQueue *queue = malloc(sizeof(*queue)); UAsyncQueue *queue = malloc(sizeof(*queue));
if (!queue) if (!queue)
return NULL; return NULL;
...@@ -49,7 +48,9 @@ UAsyncQueue *async_queue_new(void) ...@@ -49,7 +48,9 @@ UAsyncQueue *async_queue_new(void)
return queue; return queue;
error: error:
async_queue_free(queue); if (queue->queue)
queue_free(queue->queue);
free(queue);
return NULL; return NULL;
} }
...@@ -58,8 +59,16 @@ void async_queue_free(UAsyncQueue *queue) ...@@ -58,8 +59,16 @@ void async_queue_free(UAsyncQueue *queue)
if (!queue) if (!queue)
return; return;
pthread_mutex_lock(&queue->mutex);
if (queue->is_waiting) {
queue->is_waiting = 0;
pthread_cond_signal(&queue->cond);
}
pthread_mutex_unlock(&queue->mutex); pthread_mutex_unlock(&queue->mutex);
queue_free(queue->queue); queue_free(queue->queue);
pthread_cond_destroy(&queue->cond);
pthread_mutex_destroy(&queue->mutex);
free(queue); free(queue);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment