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.
This commit is contained in:
parent
7a220b37db
commit
08a1c61a4d
11
lib/plist.c
11
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
|
||||
|
Loading…
Reference in New Issue
Block a user