erofs-utils: fix pthread resource leak in erofs_alloc_workqueue()
PATCH 1/1 erofs-utils: fix pthread resource leak in erofs_alloc_workqueue()
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 <[email protected]>
--- lib/workqueue.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/workqueue.c +5 -1
@@ -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);
Signature · 1 line
2.43.0