From da7f979a07979a8788f5b2af1aadad361aaeced1 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 6 Oct 2017 21:40:08 -0400 Subject: [PATCH] lib: Free workqueue memory leak on free When free'ing the workqueue if you have items on the workqueue you should free the memory associated with it. Additionally move the work_queue_item_remove function to allow for static to be awesome Signed-off-by: Donald Sharp --- lib/workqueue.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/workqueue.c b/lib/workqueue.c index 643ed2d2b8..952012a006 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -57,6 +57,22 @@ static void work_queue_item_free(struct work_queue_item *item) return; } +static void work_queue_item_remove(struct work_queue *wq, + struct work_queue_item *item) +{ + assert(item && item->data); + + /* call private data deletion callback if needed */ + if (wq->spec.del_item_data) + wq->spec.del_item_data(wq, item->data); + + work_queue_item_dequeue(wq, item); + + work_queue_item_free(item); + + return; +} + /* create new work queue */ struct work_queue *work_queue_new(struct thread_master *m, const char *queue_name) @@ -90,6 +106,12 @@ void work_queue_free(struct work_queue *wq) if (wq->thread != NULL) thread_cancel(wq->thread); + while (!work_queue_empty(wq)) { + struct work_queue_item *item = work_queue_last_item(wq); + + work_queue_item_remove(wq, item); + } + listnode_delete(work_queues, wq); XFREE(MTYPE_WORK_QUEUE_NAME, wq->name); @@ -137,22 +159,6 @@ void work_queue_add(struct work_queue *wq, void *data) return; } -static void work_queue_item_remove(struct work_queue *wq, - struct work_queue_item *item) -{ - assert(item && item->data); - - /* call private data deletion callback if needed */ - if (wq->spec.del_item_data) - wq->spec.del_item_data(wq, item->data); - - work_queue_item_dequeue(wq, item); - - work_queue_item_free(item); - - return; -} - static void work_queue_item_requeue(struct work_queue *wq, struct work_queue_item *item) { work_queue_item_dequeue(wq, item); -- 2.39.5