From 08a1c61a4d2916bf7a731356ddbbe6e15ba14572 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 27 Dec 2019 14:27:51 +0100 Subject: [PATCH] xbps_array_foreach_cb_multi: error out if pthread_create(3) fails. We do not want to continue processing more threads if pthread_create(3) fails, rather return an error. This is for #182 but not yet fixed, there might be a memleak somewhere. --- lib/plist.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/plist.c b/lib/plist.c index b26e2893..7a4008a8 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -102,7 +102,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp, { struct thread_data *thd; unsigned int arraycount, slicecount; - int rv = 0, maxthreads; + int rv = 0, error = 0 , maxthreads; unsigned int reserved; pthread_spinlock_t reserved_lock; @@ -150,8 +150,11 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp, thd[i].slicecount = slicecount; thd[i].arraycount = arraycount; - pthread_create(&thd[i].thread, NULL, - array_foreach_thread, &thd[i]); + if ((rv = pthread_create(&thd[i].thread, NULL, array_foreach_thread, &thd[i])) != 0) { + error = rv; + break; + } + } /* wait for all threads */ for (int i = 0; i < maxthreads; i++) @@ -160,7 +163,7 @@ xbps_array_foreach_cb_multi(struct xbps_handle *xhp, free(thd); pthread_spin_destroy(&reserved_lock); - return rv; + return error ? error : rv; } int