From d62bafee9fc38f8b9653c531e1861e83dcba4618 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Mon, 3 Oct 2022 16:41:58 -0400 Subject: [PATCH] Fix memory leak found by GCC static analyzer GCC 12.1.1_p20220625's -fanalyzer found and reported this. Reviewed-by: Brian Behlendorf Reviewed-by: Damian Szuberski Signed-off-by: Richard Yao Closes #13975 --- lib/libzpool/taskq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libzpool/taskq.c b/lib/libzpool/taskq.c index b1e71e998..a2e457ef9 100644 --- a/lib/libzpool/taskq.c +++ b/lib/libzpool/taskq.c @@ -319,7 +319,9 @@ taskq_destroy(taskq_t *tq) tq->tq_minalloc = 0; while (tq->tq_nalloc != 0) { ASSERT(tq->tq_freelist != NULL); - task_free(tq, task_alloc(tq, KM_SLEEP)); + taskq_ent_t *tqent_nexttq = tq->tq_freelist->tqent_next; + task_free(tq, tq->tq_freelist); + tq->tq_freelist = tqent_nexttq; } mutex_exit(&tq->tq_lock);