From: Ivan Maidanski Date: Mon, 27 Feb 2012 16:44:21 +0000 (+0400) Subject: Report GC_pthread_join/detach failure with appropriate message X-Git-Tag: gc7_3alpha2~78 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c6693ba824272c52f7210c0658b35976640c34b;p=gc Report GC_pthread_join/detach failure with appropriate message * win32_threads.c (GC_pthread_join): Call GC_lookup_pthread only if needed (in case of pthreads-w32 target). * win32_threads.c (GC_pthread_join, GC_pthread_detach): If no thread is found by GC_lookup_pthread (e.g., the thread has not been created by GC_pthread_create) then abort with the appropriate message (instead of null pointer dereference). --- diff --git a/win32_threads.c b/win32_threads.c index fe206520..920cb61a 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2516,14 +2516,15 @@ GC_INNER void GC_thr_init(void) result = pthread_join(pthread_id, retval); -# ifdef GC_WIN32_PTHREADS - /* win32_pthreads id are unique */ - t = GC_lookup_pthread(pthread_id); -# endif - if (!GC_win32_dll_threads) { DCL_LOCK_STATE; +# ifdef GC_WIN32_PTHREADS + /* win32_pthreads id are unique */ + t = GC_lookup_pthread(pthread_id); + if (NULL == t) ABORT("Thread not registered"); +# endif + LOCK(); GC_delete_gc_thread(t); UNLOCK(); @@ -2681,6 +2682,7 @@ GC_INNER void GC_thr_init(void) UNLOCK(); result = pthread_detach(thread); if (result == 0) { + if (NULL == t) ABORT("Thread not registered"); LOCK(); t -> flags |= DETACHED; /* Here the pthread thread id may have been recycled. */