io-wq: fix memory leak in create_io_worker()
PATCH 1/1 io-wq: fix memory leak in create_io_worker()
We should free memory the variable worker point to in fail path.
--- fs/io-wq.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fs/io-wq.c +10 -10
@@ -737,15 +737,8 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)__set_current_state (TASK_RUNNING ); worker =kzalloc_node (sizeof (*worker),GFP_KERNEL , wqe->node); -if (!worker) { -fail: -atomic_dec (&acct->nr_running); -raw_spin_lock (&wqe->lock); - acct->nr_workers--; -raw_spin_unlock (&wqe->lock); -io_worker_ref_put (wq); -return false; - } +if (!worker) + goto fail;refcount_set (&worker->ref,1 ); worker->wqe = wqe;
@@ -759,7 +752,14 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)if (!IS_ERR (tsk)) {io_init_new_worker (wqe, worker, tsk); }else if (!io_should_retry_thread (PTR_ERR (tsk))) { - goto fail; +kfree (worker); +fail: +atomic_dec (&acct->nr_running); +raw_spin_lock (&wqe->lock); + acct->nr_workers--; +raw_spin_unlock (&wqe->lock); +io_worker_ref_put (wq); +return false; }else {INIT_WORK (&worker->work, io_workqueue_create);schedule_work (&worker->work);
Signature · 1 line
2.24.4
Jens Axboe
maintainerQuoted 1 line · Hao Xu
We should free memory the variable worker point to in fail path.
I think this one is missing a few paths where it can also happen, once punted.
Signature · 1 line
Jens Axboe
Quoted 5 lines · Jens Axboe
Quoted 1 line · Hao Xu
We should free memory the variable worker point to in fail path.
I think this one is missing a few paths where it can also happen, once punted.
True. I browse the code again and I think Qiang.zhang's patch should be fine.
Quoted 1 line
Jens Axboe
maintainerQuoted 8 lines · Hao Xu
Quoted 5 lines · Jens Axboe
Quoted 1 line · Hao Xu
We should free memory the variable worker point to in fail path.
I think this one is missing a few paths where it can also happen, once punted.
True. I browse the code again and I think Qiang.zhang's patch should be fine.
Yes agree, that one looks complete. I have applied it.
Signature · 1 line
Jens Axboe