]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Free workqueue memory leak on free 1305/head
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sat, 7 Oct 2017 01:40:08 +0000 (21:40 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 11 Oct 2017 14:00:54 +0000 (10:00 -0400)
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 <sharpd@cumulusnetworks.com>
lib/workqueue.c

index 643ed2d2b895938b109763e893b080201aba74e2..952012a006efbb10b50be0889508f6432443b8d1 100644 (file)
@@ -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);