diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-10-11 08:54:33 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-11-14 21:50:43 +0300 |
commit | 18b384c5c3548f8a960c2382c645aed55ab98874 (patch) | |
tree | 007e278372b95079650c77631849f62ff8b77d9b | |
parent | ccecdaf04411b65f5badbeaae36f50c9c216d37b (diff) | |
download | bdwgc-18b384c5c3548f8a960c2382c645aed55ab98874.tar.gz |
Fix missing result check of pthread_attr_getdetachstate in pthread_create
* pthread_support.c (pthread_create): Call ABORT() if
pthread_attr_getdetachstate() has failed.
* win32_threads.c [GC_PTHREADS] (GC_pthread_create): Likewise.
* win32_threads.c [GC_PTHREADS] (start_info.detached): Change type from
GC_bool to int (to match the type of the 2nd argument of
pthread_attr_getdetachstate).
-rw-r--r-- | pthread_support.c | 3 | ||||
-rw-r--r-- | win32_threads.c | 11 |
2 files changed, 6 insertions, 8 deletions
diff --git a/pthread_support.c b/pthread_support.c index e17e4c54..824740a6 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -2018,7 +2018,8 @@ GC_INNER_PTHRSTART GC_thread GC_start_rtn_prepare_thread( if (NULL == attr) { detachstate = PTHREAD_CREATE_JOINABLE; } else { - pthread_attr_getdetachstate(attr, &detachstate); + if (pthread_attr_getdetachstate(attr, &detachstate) != 0) + ABORT("pthread_attr_getdetachstate failed"); } if (PTHREAD_CREATE_DETACHED == detachstate) my_flags |= DETACHED; si.flags = my_flags; diff --git a/win32_threads.c b/win32_threads.c index af9e0800..f3edc34f 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2759,7 +2759,7 @@ GC_INNER void GC_thr_init(void) struct start_info { void *(*start_routine)(void *); void *arg; - GC_bool detached; + int detached; }; GC_API int GC_pthread_join(pthread_t pthread_id, void **retval) @@ -2837,12 +2837,9 @@ GC_INNER void GC_thr_init(void) si -> arg = arg; GC_dirty(si); REACHABLE_AFTER_DIRTY(arg); - if (attr != 0 && - pthread_attr_getdetachstate(attr, &si->detached) - == PTHREAD_CREATE_DETACHED) { - si->detached = TRUE; - } - + if (attr != NULL + && pthread_attr_getdetachstate(attr, &(si -> detached)) != 0) + ABORT("pthread_attr_getdetachstate failed"); # ifdef DEBUG_THREADS GC_log_printf("About to create a thread from %p(0x%lx)\n", (void *)GC_PTHREAD_PTRVAL(pthread_self()), |