[PATCH] erofs-utils: fix pthread resource leak in erofs_alloc_workqueue()

Utkal Singh singhutkal015 at gmail.com
Wed Apr 1 17:23:55 AEDT 2026


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 at 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



More information about the Linux-erofs mailing list