kernel/workqueue.c: kfree issue, need check flag 'WQ_UNBOUND' when processing failure.
PATCH 1/1 kernel/workqueue.c: kfree issue, need check flag 'WQ_UNBOUND' when processing failure.
When failure occurs in __alloc_workqueue_key(), if 'flags' has 'WQ_UNBOUND', the destroy_workqueue() will not release 'wq'.
In this situation, we need release it, or will cause memory leak.
And also simplify the related code.
--- kernel/workqueue.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
kernel/workqueue.c +5 -4
@@ -4167,12 +4167,13 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt,return wq; -err_free_wq: -free_workqueue_attrs (wq->unbound_attrs); -kfree (wq); -return NULL ; err_destroy:destroy_workqueue (wq); +if (flags &WQ_UNBOUND ) { +err_free_wq: +free_workqueue_attrs (wq->unbound_attrs); +kfree (wq); + }return NULL ; }EXPORT_SYMBOL_GPL (__alloc_workqueue_key);
Signature · 1 line
1.7.7.6
Tejun Heo
maintainerkernel/workqueue.c struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · line 4176
Quoted 7 lines · Chen Gang
err_destroy:kernel/workqueue.c +5
-0destroy_workqueue (wq); +if (flags &WQ_UNBOUND ) { +err_free_wq: +free_workqueue_attrs (wq->unbound_attrs); +kfree (wq); + }
Doesn't the above make the code free wq twice on after err_destroy?
Signature · 1 line
tejun
Quoted 11 lines · Tejun Heo
kernel/workqueue.c struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · line 4176
Quoted 7 lines · Chen Gang
err_destroy:kernel/workqueue.c +5
-0destroy_workqueue (wq); +if (flags &WQ_UNBOUND ) { +err_free_wq: +free_workqueue_attrs (wq->unbound_attrs); +kfree (wq); + }Doesn't the above make the code free wq twice on after
err_destroy?
Oh, it is my fault. I did not see the put_pwq_unlocked() in details, next I should read the code carefully.
Thanks.
Signature · 3 lines
Chen Gang Asianux Corporation
Tejun Heo
maintainerQuoted 13 lines · Chen Gang
Quoted 11 lines · Tejun Heo
kernel/workqueue.c struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · line 4176
Quoted 7 lines · Chen Gang
err_destroy:kernel/workqueue.c +5
-0destroy_workqueue (wq); +if (flags &WQ_UNBOUND ) { +err_free_wq: +free_workqueue_attrs (wq->unbound_attrs); +kfree (wq); + }Doesn't the above make the code free wq twice on after
err_destroy?
Quoted 2 lines
Oh, it is my fault. I did not see the
put_pwq_unlocked()in details, next I should read the code carefully.
We're still leaking unbound_attrs in the failure path, right? We can probably just add unconditional free_workqueue_attrs() in err_free_wq?
Thanks.
Signature · 1 line
tejun
Quoted 14 lines · Tejun Heo
Quoted 13 lines · Chen Gang
Quoted 11 lines · Tejun Heo
kernel/workqueue.c struct workqueue_struct *__alloc_workqueue_key(const char *fmt, · line 4176
Quoted 7 lines · Chen Gang
err_destroy:kernel/workqueue.c +5
-0destroy_workqueue (wq); +if (flags &WQ_UNBOUND ) { +err_free_wq: +free_workqueue_attrs (wq->unbound_attrs); +kfree (wq); + }Doesn't the above make the code free wq twice on after
err_destroy?
Quoted 6 lines
Quoted 2 lines
Oh, it is my fault. I did not see the
put_pwq_unlocked()in details, next I should read the code carefully.We're still leaking
unbound_attrsin the failure path, right? We can probably just add unconditionalfree_workqueue_attrs()inerr_free_wq?
It seems that it already done, the related patch is provided by you :
"6029a91 workqueue: add workqueue->unbound_attrs".
Please check.
Thanks.
Signature · 3 lines
Chen Gang Asianux Corporation