Skip to contentSkip to conversation

kernel/workqueue.c: kfree issue, need check flag 'WQ_UNBOUND' when processing failure.

PATCH In review Chen Gang 2 participants 5 messages May 14, 2013 – May 16, 2013 Workqueue

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

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
index 1ae6028..bf644d4 100644
@@ -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
maintainer
#1 lore raw

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 -0
 	destroy_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
author
#2 lore raw
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 -0
 	destroy_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
maintainer
#3 lore raw
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 -0
 	destroy_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
author
#4 lore raw
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 -0
 	destroy_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_attrs in the failure path, right? We can probably just add unconditional free_workqueue_attrs() in err_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