diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-10-11 08:54:33 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-11-15 11:03:21 +0300 |
commit | 869cd0a026e508e0a62cce5056dbd445ff7854ed (patch) | |
tree | c59b1d308a6726d9aa2502b57bc1ae5d189d961a | |
parent | 7f53221c72ef77209c9f4c89a38c1ba8ced78ddd (diff) | |
download | bdwgc-869cd0a026e508e0a62cce5056dbd445ff7854ed.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 bc02a0f6..00d374fc 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -1796,7 +1796,8 @@ GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_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 5041543c..73f1e7a9 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2668,7 +2668,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) @@ -2740,12 +2740,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", GC_PTHREAD_PTRVAL(pthread_self()), |