Call pthread_attr_destroy even if pthread_create failed

As suggested in
63bfab9975 (commitcomment-66542462)

Also, check for errors.
This commit is contained in:
Johannes Altmanninger 2022-02-19 14:10:47 +01:00
parent 63d7386a36
commit 2f5edfd617

View File

@ -362,10 +362,14 @@ bool make_detached_pthread(void *(*func)(void *), void *param) {
err = pthread_create(&thread, &thread_attr, func, param); err = pthread_create(&thread, &thread_attr, func, param);
if (err == 0) { if (err == 0) {
FLOGF(iothread, "pthread %d spawned", thread); FLOGF(iothread, "pthread %d spawned", thread);
pthread_attr_destroy(&thread_attr);
} else { } else {
perror("pthread_create"); perror("pthread_create");
} }
int err2 = pthread_attr_destroy(&thread_attr);
if (err2 != 0) {
perror("pthread_attr_destroy");
err = err2;
}
} else { } else {
perror("pthread_attr_setdetachstate"); perror("pthread_attr_setdetachstate");
} }