]> granicus.if.org Git - gc/commitdiff
Report GC_pthread_join/detach failure with appropriate message
authorIvan Maidanski <ivmai@mail.ru>
Mon, 27 Feb 2012 16:44:21 +0000 (20:44 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 27 Feb 2012 16:46:26 +0000 (20:46 +0400)
* 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).

win32_threads.c

index fe2065206069468cefe48e452b265c9ce195ae28..920cb61a5e6fe3e1baa4590e74ce1a53de130197 100644 (file)
@@ -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. */