From 45cdc834c4b25b09d9263fc4b6a6c2b6432abdc6 Mon Sep 17 00:00:00 2001 From: normal Date: Tue, 3 Jul 2018 08:30:16 +0000 Subject: [PATCH] thread_pthread.c (native_thread_destroy): clear native TSD pointer mwrap interposes malloc functions and checks for GVL existence to determine Ruby source locations of malloc calls. pthread_getattr_np (from get_stack) may call realloc to get the CPU set size; so when using the thread-cache, ruby_thread_has_gvl_p() may hit a false positive on reused threads with lingering rb_thread_t in thread-specific data. This was causing mwrap to call rb_source_location_cstr() and crash because it was pointed to a zero ec->cfp->iseq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/thread_pthread.c b/thread_pthread.c index 401fc0c774..60a3b13a68 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -427,15 +427,22 @@ native_thread_init(rb_thread_t *th) ruby_thread_set_native(th); } +#ifndef USE_THREAD_CACHE +#define USE_THREAD_CACHE 1 +#endif + static void native_thread_destroy(rb_thread_t *th) { rb_native_cond_destroy(&th->native_thread_data.sleep_cond); -} -#ifndef USE_THREAD_CACHE -#define USE_THREAD_CACHE 1 -#endif + /* + * prevent false positive from ruby_thread_has_gvl_p if that + * gets called from an interposing function wrapper + */ + if (USE_THREAD_CACHE) + ruby_thread_set_native(0); +} #if USE_THREAD_CACHE static rb_thread_t *register_cached_thread_and_wait(void);