From 50493c38d739a0898cb7b96df8603e957fca9dae Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 1 Apr 2019 10:53:39 +0100 Subject: [PATCH] Don't use pthread storage for exceptions. If an exception unwinds to the top of a thread, the process will die, so don't worry about leaking memory for this case. --- eh_personality.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/eh_personality.c b/eh_personality.c index b41e375..410d177 100644 --- a/eh_personality.c +++ b/eh_personality.c @@ -7,10 +7,6 @@ #include "class.h" #include "objcxx_eh.h" -#ifndef NO_PTHREADS -#include -#endif - #ifndef DEBUG_EXCEPTIONS #define DEBUG_LOG(...) #else @@ -530,53 +526,16 @@ struct thread_data struct objc_exception *caughtExceptions; }; -// IF we don't have pthreads, then we fall back to using a per-thread -// structure. This will leak memory if we terminate any threads with -// exceptions in-flight. -#ifdef NO_PTHREADS static __thread struct thread_data thread_data; -#else -static void clean_tls(void *td) -{ - struct thread_data *data = td; -} - -static pthread_key_t key; -static void init_key(void) -{ - pthread_key_create(&key, clean_tls); -} -#endif static struct thread_data *get_thread_data(void) { -#ifndef NO_PTHREADS - static pthread_once_t once_control = PTHREAD_ONCE_INIT; - pthread_once(&once_control, init_key); - struct thread_data *td = pthread_getspecific(key); - if (td == NULL) - { - td = calloc(sizeof(struct thread_data), 1); - pthread_setspecific(key, td); - if (pthread_getspecific(key) == NULL) - { - fprintf(stderr, "Unable to allocate thread-local storage for exceptions\n"); - } - } - return td; -#else return &thread_data; -#endif } static struct thread_data *get_thread_data_fast(void) { -#ifndef NO_PTHREADS - struct thread_data *td = pthread_getspecific(key); - return td; -#else return &thread_data; -#endif } id objc_begin_catch(struct _Unwind_Exception *exceptionObject)