From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@linux.alibaba.com, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] erofs-utils: fix pthread resource leak in erofs_alloc_workqueue()
Date: Wed, 1 Apr 2026 06:23:55 +0000 [thread overview]
Message-ID: <20260401062356.5320-1-singhutkal015@gmail.com> (raw)
When malloc() fails to allocate wq->workers, erofs_alloc_workqueue()
returns -ENOMEM without cleaning up previously initialized mutex and
condition variables. Destroy them before returning to avoid a resource leak.
Fixes: 13f7268 ("erofs-utils: introduce multi-threading framework")
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
lib/workqueue.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 4a1a957..1f3fa7c 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -90,8 +90,12 @@ int erofs_alloc_workqueue(struct erofs_workqueue *wq, unsigned int nworker,
pthread_cond_init(&wq->cond_full, NULL);
wq->workers = malloc(nworker * sizeof(pthread_t));
- if (!wq->workers)
+ if (!wq->workers) {
+ pthread_mutex_destroy(&wq->lock);
+ pthread_cond_destroy(&wq->cond_empty);
+ pthread_cond_destroy(&wq->cond_full);
return -ENOMEM;
+ }
for (i = 0; i < nworker; i++) {
ret = -pthread_create(&wq->workers[i], NULL, worker_thread, wq);
--
2.43.0
reply other threads:[~2026-04-01 6:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260401062356.5320-1-singhutkal015@gmail.com \
--to=singhutkal015@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox