[PATCH v3] erofs-utils: fix thread join loop in erofs_destroy_workqueue
Nithurshen
nithurshen.dev at gmail.com
Wed Mar 18 17:03:19 AEDT 2026
Currently, `erofs_destroy_workqueue` returns immediately if a single
`pthread_join` fails. However, it does not log the failure, making it
difficult to debug if a worker thread gets stuck.
Add an error log when `pthread_join` fails. Retain the early return
behavior to safely abort the teardown process, ensuring we do not
free the synchronization primitives and worker array while threads
are potentially still alive (avoiding a use after free).
Signed-off-by: Nithurshen <nithurshen.dev at gmail.com>
---
lib/workqueue.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 18ee0f9..4a1a957 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0
#include <pthread.h>
#include <stdlib.h>
+#include "erofs/print.h"
#include "erofs/workqueue.h"
static void *worker_thread(void *arg)
@@ -53,10 +54,14 @@ int erofs_destroy_workqueue(struct erofs_workqueue *wq)
while (wq->nworker) {
int ret = -pthread_join(wq->workers[wq->nworker - 1], NULL);
- if (ret)
+ if (ret) {
+ erofs_err("failed to join worker thread %u: %d",
+ wq->nworker - 1, ret);
return ret;
+ }
--wq->nworker;
}
+
free(wq->workers);
pthread_mutex_destroy(&wq->lock);
pthread_cond_destroy(&wq->cond_empty);
--
2.43.0
More information about the Linux-erofs
mailing list